]> git.ozlabs.org Git - ccan/blobdiff - ccan/jmap/test/run-ptridx-type.c
jmap: fix jmap_free, tests.
[ccan] / ccan / jmap / test / run-ptridx-type.c
index 83642a8e68c36d7f7623199795e8eea0fe2d6d6c..20a604a1fcde6f797a30fe1575918a92ba74c17e 100644 (file)
@@ -17,26 +17,26 @@ 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 idx *idx[NUM], *index;
+       struct foo *foo[NUM+1], **foop;
+       struct idx *idx[NUM+1], *index;
 
        unsigned int i;
 
        plan_tests(25 + NUM*2 + 6);
-       for (i = 0; i < NUM; i++)
+       for (i = 0; i < NUM+1; i++)
                foo[i] = malloc(20);
 
        qsort(foo, NUM, sizeof(foo[0]), cmp_ptr);
 
        /* idx[i] == foo[i] + 1, for easy checking */
-       for (i = 0; i < NUM; i++)
+       for (i = 0; i < NUM+1; i++)
                idx[i] = (void *)((char *)foo[i] + 1);
 
        map = jmap_foo_new();
        ok1(jmap_foo_error(map) == NULL);
 
-       ok1(jmap_foo_test(map, idx[i]) == false);
-       ok1(jmap_foo_get(map, idx[i]) == (struct foo *)NULL);
+       ok1(jmap_foo_test(map, idx[NUM]) == false);
+       ok1(jmap_foo_get(map, idx[NUM]) == (struct foo *)NULL);
        ok1(jmap_foo_count(map) == 0);
        ok1(jmap_foo_first(map) == (struct idx *)NULL);
        ok1(jmap_foo_del(map, idx[0]) == false);
@@ -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();
 }