4 #include <ccan/talloc/talloc.h>
5 #include <ccan/failtest/failtest_override.h>
6 #include <ccan/failtest/failtest.h>
8 #include <ccan/rfc822/rfc822.h>
12 /* failtest limitations mean we need these wrappers to test talloc
14 static void *malloc_wrapper(size_t size)
19 static void free_wrapper(void *ptr)
24 static void *realloc_wrapper(void *ptr, size_t size)
26 return realloc(ptr, size);
30 static void allocation_failure_exit(const char *s)
32 fprintf(stderr, "Allocation failure: %s", s);
37 static bool allocation_failed = false;
39 static void allocation_failure_continue(const char *s)
41 fprintf(stderr, "Allocation failure: %s", s);
42 allocation_failed = true;
45 void allocation_failure_check(void)
47 if (allocation_failed) {
48 fprintf(stderr, "Exiting due to earlier failed allocation\n");
53 void failtest_setup(int argc, char *argv[])
55 failtest_init(argc, argv);
56 rfc822_set_allocation_failure_handler(allocation_failure_continue);
57 talloc_set_allocator(malloc_wrapper, free_wrapper, realloc_wrapper);