diff options
author | yzrh <yzrh@noema.org> | 2022-12-22 11:22:41 +0000 |
---|---|---|
committer | yzrh <yzrh@noema.org> | 2022-12-22 19:48:48 +0000 |
commit | ac3b1dda63944f2cc8caaa52344774255e1956c8 (patch) | |
tree | 2fb8b24fbfe8002f39288926fa06c71100102868 /src/pdf_cnki.c | |
parent | 63728e1340a27b7ae629a747229871f3dc670de5 (diff) | |
download | melon-ac3b1dda63944f2cc8caaa52344774255e1956c8.tar.gz melon-ac3b1dda63944f2cc8caaa52344774255e1956c8.tar.zst |
Fix memory leak and data type.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src/pdf_cnki.c')
-rw-r--r-- | src/pdf_cnki.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/pdf_cnki.c b/src/pdf_cnki.c index 84274b8..a1c7a09 100644 --- a/src/pdf_cnki.c +++ b/src/pdf_cnki.c @@ -106,6 +106,26 @@ _outline(pdf_object_t **pdf, object_outline_tree_t **outline_tree, int id, int * return 0; } +static int +_outline_free(object_outline_tree_t **outline_tree) +{ + object_outline_tree_t *ptr = *outline_tree; + for (;;) { + if (ptr->right != NULL) + _outline_free(&ptr->right); + + if (ptr->left != NULL) { + ptr = ptr->left; + free(ptr->up); + } else { + free(ptr); + break; + } + } + + return 0; +} + int pdf_cnki_outline(pdf_object_t **pdf, object_outline_t **outline, int **ids) { @@ -119,8 +139,7 @@ pdf_cnki_outline(pdf_object_t **pdf, object_outline_t **outline, int **ids) int *ret; _outline(pdf, &outline_tree->left, outline_tree->id, &ret); - - free(outline_tree); + _outline_free(&outline_tree); snprintf(buf, 128, "<<\n/Type Outlines\n/First %d 0 R\n/Last %d 0 R\n/Count %d\n>>", |