ccanlint: handle nested modules when mentioned in examples.
[ccan] / ccan / tal / test / run-groups-grow.c
1 #define CCAN_TAL_DEBUG
2 #include <ccan/tal/tal.h>
3 #include <ccan/tal/tal.c>
4 #include <ccan/tap/tap.h>
5
6 static size_t num_allocated;
7
8 static void *alloc_account(size_t len)
9 {
10         num_allocated++;
11         return malloc(len);
12 }
13
14 static void free_account(void *p)
15 {
16         num_allocated--;
17         return free(p);
18 }
19
20 #define NUM_ALLOCS 1000
21
22 int main(void)
23 {
24         void *p, *c[NUM_ALLOCS];
25         int i;
26         size_t allocated_after_first;
27
28         plan_tests(1);
29
30         tal_set_backend(alloc_account, NULL, free_account, NULL);
31
32         p = tal(NULL, char);
33         c[0] = tal(p, char);
34
35         allocated_after_first = num_allocated;
36         for (i = 1; i < NUM_ALLOCS; i++)
37                 c[i] = tal(p, char);
38
39         /* Now free them all. */
40         for (i = 0; i < NUM_ALLOCS; i++)
41                 tal_free(c[i]);
42
43         /* We can expect some residue from having any child, but limited! */
44         ok1(num_allocated <= allocated_after_first);
45         return exit_status();
46 }