summaryrefslogtreecommitdiff
path: root/ccan/tal/test/run-free.c
blob: 37d03cd6ff4cbd0233950f0808129e939f9975e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <ccan/tal/tal.h>
#include <ccan/tal/tal.c>
#include <ccan/tap/tap.h>

static void destroy_errno(char *p UNNEEDED)
{
	/* Errno restored for all the destructors. */
	ok1(errno == EINVAL);
	errno = ENOENT;
}

int main(void)
{
	char *p;

	plan_tests(5);

	p = tal(NULL, char);
	ok1(tal_add_destructor(p, destroy_errno));
	ok1(tal_add_destructor(p, destroy_errno));

	/* Errno save/restored across free. */
	errno = EINVAL;
	tal_free(p);
	ok1(errno == EINVAL);

	tal_cleanup();
	return exit_status();
}