From 409acceffa5698853dc63f143df960849be8dc32 Mon Sep 17 00:00:00 2001 From: yzrh Date: Wed, 27 Jan 2021 16:42:52 +0000 Subject: Fix memory leak. --- src/cnki.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/cnki.c') diff --git a/src/cnki.c b/src/cnki.c index 6866f8e..5f120d0 100644 --- a/src/cnki.c +++ b/src/cnki.c @@ -44,10 +44,19 @@ cnki_destroy(cnki_t **param) if (*param != NULL) { if ((*param)->file_stat != NULL) free((*param)->file_stat); - if ((*param)->object_outline != NULL) - free((*param)->object_outline); - if ((*param)->object_hn != NULL) - free((*param)->object_hn); + + object_outline_t *ptr_outline; + while ((ptr_outline = (*param)->object_outline) != NULL) { + (*param)->object_outline = (*param)->object_outline->next; + free(ptr_outline); + } + + object_hn_t *ptr_hn; + while ((ptr_hn = (*param)->object_hn) != NULL) { + (*param)->object_hn = (*param)->object_hn->next; + free(ptr_hn); + } + free(*param); } } -- cgit v1.2.3