Browse Source

jmap: fix jmap_free, tests.

Memory leak in tests revealed bug in jmap_free.  Also, out-by-one
error.
Rusty Russell 14 years ago
parent
commit
03f017e9af
3 changed files with 8 additions and 2 deletions
  1. 1 1
      ccan/jmap/jmap.c
  2. 4 1
      ccan/jmap/test/run-ptridx-type.c
  3. 3 0
      ccan/jmap/test/run-uintidx-type.c

+ 1 - 1
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);
 }

+ 4 - 1
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();
 }

+ 3 - 0
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();
 }