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);
37 ok1(my_malloc_count == 1);
38 ok1(my_free_count == 0);
39 ok1(my_realloc_count == 0);
41 p1 = talloc_realloc(NULL, p1, int, 10000);
42 ok1(my_malloc_count == 1);
43 ok1(my_free_count == 0);
44 ok1(my_realloc_count == 1);
47 ok1(my_malloc_count == 2);
48 ok1(my_free_count == 0);
49 ok1(my_realloc_count == 1);
52 ok1(my_malloc_count == 2);
53 ok1(my_free_count == 2);
54 ok1(my_realloc_count == 1);
56 failtest_exit(exit_status());