tal: handle take() pointers more carefully.
[ccan] / ccan / tal / test / run-take-free-assert.c
1 #include <ccan/tal/tal.h>
2 #include <ccan/tal/tal.c>
3 #include <ccan/tap/tap.h>
4 #include <signal.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
7 #include <unistd.h>
8
9 int main(void)
10 {
11         int status;
12         char *p;
13
14         plan_tests(4);
15
16         /* Test direct free. */
17         switch (fork()) {
18         case 0:
19                 tal_free(take(tal(NULL, char)));
20                 exit(2);
21         case -1:
22                 exit(1);
23         default:
24                 wait(&status);
25                 ok1(WIFSIGNALED(status));
26                 ok1(WTERMSIG(status) == SIGABRT);
27         }
28
29         /* Test indirect free. */
30         switch (fork()) {
31         case 0:
32                 p = tal(NULL, char);
33                 take(tal(p, char));
34                 tal_free(p);
35                 exit(2);
36         case -1:
37                 exit(1);
38         default:
39                 wait(&status);
40                 ok1(WIFSIGNALED(status));
41                 ok1(WTERMSIG(status) == SIGABRT);
42         }
43         return exit_status();
44 }