Commit 03f017e9 authored by Rusty Russell's avatar Rusty Russell

jmap: fix jmap_free, tests.

Memory leak in tests revealed bug in jmap_free.  Also, out-by-one
error.
parent 3baf0eff
...@@ -43,6 +43,6 @@ const char *jmap_error_(struct jmap *map) ...@@ -43,6 +43,6 @@ const char *jmap_error_(struct jmap *map)
void jmap_free(const struct jmap *map) void jmap_free(const struct jmap *map)
{ {
free((char *)map->errstr); free((char *)map->errstr);
Judy1FreeArray((PPvoid_t)&map->judy, PJE0); JudyLFreeArray((PPvoid_t)&map->judy, PJE0);
free((void *)map); free((void *)map);
} }
...@@ -17,7 +17,7 @@ static int cmp_ptr(const void *a, const void *b) ...@@ -17,7 +17,7 @@ static int cmp_ptr(const void *a, const void *b)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct jmap_foo *map; struct jmap_foo *map;
struct foo *foo[NUM], **foop; struct foo *foo[NUM+1], **foop;
struct idx *idx[NUM+1], *index; struct idx *idx[NUM+1], *index;
unsigned int i; unsigned int i;
...@@ -97,5 +97,8 @@ int main(int argc, char *argv[]) ...@@ -97,5 +97,8 @@ int main(int argc, char *argv[])
ok1(jmap_foo_error(map) == NULL); ok1(jmap_foo_error(map) == NULL);
jmap_foo_free(map); jmap_foo_free(map);
for (i = 0; i < NUM+1; i++)
free(foo[i]);
return exit_status(); return exit_status();
} }
...@@ -126,5 +126,8 @@ int main(int argc, char *argv[]) ...@@ -126,5 +126,8 @@ int main(int argc, char *argv[])
ok1(jmap_foo_error(map) == NULL); ok1(jmap_foo_error(map) == NULL);
jmap_foo_free(map); jmap_foo_free(map);
for (i = 0; i < NUM; i++)
free(foo[i]);
return exit_status(); return exit_status();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment