]> git.ozlabs.org Git - ccan/commitdiff
jmap: fix jmap_free, tests.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Aug 2011 02:30:13 +0000 (12:00 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Aug 2011 02:30:13 +0000 (12:00 +0930)
Memory leak in tests revealed bug in jmap_free.  Also, out-by-one
error.

ccan/jmap/jmap.c
ccan/jmap/test/run-ptridx-type.c
ccan/jmap/test/run-uintidx-type.c

index 38b912fd200b98b1c5df8074c1a77d188306fd37..78b7ba21b98b5ac56b8e7ff28c7f52b6fc897ddd 100644 (file)
@@ -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);
 }
index aa715cf51162b70f80ed3a18d14795a69b4ed9ae..20a604a1fcde6f797a30fe1575918a92ba74c17e 100644 (file)
@@ -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();
 }
index 0dda6eddfb7224ae54a946e02d30d9c17cd32c66..2a3714278e80479494f63aa0e8bc65fdf3a1fed5 100644 (file)
@@ -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();
 }