From 03f017e9aff901d5d80bd577732543961a13c497 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 23 Aug 2011 12:00:13 +0930 Subject: [PATCH 1/1] jmap: fix jmap_free, tests. Memory leak in tests revealed bug in jmap_free. Also, out-by-one error. --- ccan/jmap/jmap.c | 2 +- ccan/jmap/test/run-ptridx-type.c | 5 ++++- ccan/jmap/test/run-uintidx-type.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ccan/jmap/jmap.c b/ccan/jmap/jmap.c index 38b912fd..78b7ba21 100644 --- a/ccan/jmap/jmap.c +++ b/ccan/jmap/jmap.c @@ -43,6 +43,6 @@ const char *jmap_error_(struct jmap *map) void jmap_free(const struct jmap *map) { free((char *)map->errstr); - Judy1FreeArray((PPvoid_t)&map->judy, PJE0); + JudyLFreeArray((PPvoid_t)&map->judy, PJE0); free((void *)map); } diff --git a/ccan/jmap/test/run-ptridx-type.c b/ccan/jmap/test/run-ptridx-type.c index aa715cf5..20a604a1 100644 --- a/ccan/jmap/test/run-ptridx-type.c +++ b/ccan/jmap/test/run-ptridx-type.c @@ -17,7 +17,7 @@ static int cmp_ptr(const void *a, const void *b) int main(int argc, char *argv[]) { struct jmap_foo *map; - struct foo *foo[NUM], **foop; + struct foo *foo[NUM+1], **foop; struct idx *idx[NUM+1], *index; unsigned int i; @@ -97,5 +97,8 @@ int main(int argc, char *argv[]) ok1(jmap_foo_error(map) == NULL); jmap_foo_free(map); + for (i = 0; i < NUM+1; i++) + free(foo[i]); + return exit_status(); } diff --git a/ccan/jmap/test/run-uintidx-type.c b/ccan/jmap/test/run-uintidx-type.c index 0dda6edd..2a371427 100644 --- a/ccan/jmap/test/run-uintidx-type.c +++ b/ccan/jmap/test/run-uintidx-type.c @@ -126,5 +126,8 @@ int main(int argc, char *argv[]) ok1(jmap_foo_error(map) == NULL); jmap_foo_free(map); + for (i = 0; i < NUM; i++) + free(foo[i]); + return exit_status(); } -- 2.39.2