4 /* Make sure it always uses our allocation/resize/free fns! */
5 static bool my_alloc_called;
7 static void *my_alloc(size_t len)
9 my_alloc_called = true;
10 return (char *)malloc(len + 16) + 16;
13 static void my_free(void *p)
15 return free((char *)p - 16);
18 static void *my_realloc(void *old, size_t new_size)
20 return (char *)realloc((char *)old - 16, new_size + 16) + 16;
23 #define free ((void (*)(void *))abort)
24 #define malloc ((void *(*)(size_t))abort)
25 #define realloc ((void *(*)(void *, size_t))abort)
27 #include <ccan/tal/tal.h>
28 #include <ccan/tal/tal.c>
29 #include <ccan/tap/tap.h>
31 #define NUM_ALLOCS 1000
33 static void destroy_p(void *p)
39 void *p, *c[NUM_ALLOCS];
43 /* Mostly we rely on the allocator (or valgrind) crashing. */
46 tal_set_backend(my_alloc, my_realloc, my_free, NULL);
51 /* Adding properties makes us allocated. */
52 tal_add_destructor(p, destroy_p);
54 tal_set_name(p, "test");
55 name = tal_asprintf(NULL, "test2");
56 tal_set_name(p, name);
57 /* makes us free old name */
58 tal_set_name(p, name);
61 /* Add lots of children. */
62 for (i = 0; i < NUM_ALLOCS; i++)
65 /* Now steal a few. */
66 for (i = 1; i < NUM_ALLOCS / 2; i++)
67 tal_steal(c[0], c[i]);
69 /* Now free individual ones.. */
70 for (i = NUM_ALLOCS / 2; i < NUM_ALLOCS; i++)
73 /* Finally, free the parent. */