From ac3b1dda63944f2cc8caaa52344774255e1956c8 Mon Sep 17 00:00:00 2001 From: yzrh Date: Thu, 22 Dec 2022 11:22:41 +0000 Subject: Fix memory leak and data type. Signed-off-by: yzrh --- src/pdf_cnki.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/pdf_cnki.c') 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>>", -- cgit v1.2.3