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)
19 static void *my_realloc(void *old, size_t new_size)
21 return (char *)realloc((char *)old - 16, new_size + 16) + 16;
24 #define free ((void (*)(void *))abort)
25 #define malloc ((void *(*)(size_t))abort)
26 #define realloc ((void *(*)(void *, size_t))abort)
28 #include <ccan/tal/tal.h>
29 #include <ccan/tal/tal.c>
30 #include <ccan/tap/tap.h>
32 #define NUM_ALLOCS 1000
34 static void destroy_p(void *p UNNEEDED)
40 void *p, *c[NUM_ALLOCS];
44 /* Mostly we rely on the allocator (or valgrind) crashing. */
47 tal_set_backend(my_alloc, my_realloc, my_free, NULL);
52 /* Adding properties makes us allocated. */
53 tal_add_destructor(p, destroy_p);
55 tal_set_name(p, "test");
56 name = tal_arr(NULL, char, 6);
57 strcpy(name, "test2");
58 tal_set_name(p, name);
59 /* makes us free old name */
60 tal_set_name(p, name);
63 /* Add lots of children. */
64 for (i = 0; i < NUM_ALLOCS; i++)
67 /* Now steal a few. */
68 for (i = 1; i < NUM_ALLOCS / 2; i++)
69 tal_steal(c[0], c[i]);
71 /* Now free individual ones.. */
72 for (i = NUM_ALLOCS / 2; i < NUM_ALLOCS; i++)
75 /* Finally, free the parent. */