1 #include <ccan/failtest/failtest_override.h>
2 #include <ccan/talloc/talloc.c>
4 #include <ccan/tap/tap.h>
5 #include <ccan/failtest/failtest.h>
7 static unsigned my_malloc_count, my_free_count, my_realloc_count;
9 static void *my_malloc(size_t size)
15 static void my_free(void *ptr)
21 static void *my_realloc(void *ptr, size_t size)
26 return realloc(ptr, size);
29 int main(int argc, char *argv[])
34 failtest_init(argc, argv);
35 talloc_set_allocator(my_malloc, my_free, my_realloc);
36 p1 = talloc_array(NULL, int, 10);
38 failtest_exit(exit_status());
39 ok1(my_malloc_count == 1);
40 ok1(my_free_count == 0);
41 ok1(my_realloc_count == 0);
43 p2 = talloc_realloc(NULL, p1, int, 10000);
46 failtest_exit(exit_status());
49 ok1(my_malloc_count == 1);
50 ok1(my_free_count == 0);
51 ok1(my_realloc_count == 1);
56 failtest_exit(exit_status());
58 ok1(my_malloc_count == 2);
59 ok1(my_free_count == 0);
60 ok1(my_realloc_count == 1);
63 ok1(my_malloc_count == 2);
64 ok1(my_free_count == 2);
65 ok1(my_realloc_count == 1);
67 failtest_exit(exit_status());