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/Makefile | 2 +- src/cnki.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 005f6da..ec98cf7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,7 +15,7 @@ obj = ${src:.c=.o} PREFIX = /usr/local -CFLAGS = -O3 -march=native -pipe -flto=thin -Wall -Wextra -Wno-unused-parameter +CFLAGS = -O3 -march=native -pipe -flto -Wall -Wextra -Wno-unused-parameter LDFLAGS = -Wl,-O3 -lcrypto -liconv -lz -ljbig -ljpeg -Wl,--as-needed CFLAGS += -I/usr/local/include 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