summaryrefslogtreecommitdiff
path: root/ccan/talloc/test/run-corruption1.c
blob: d6ac7da5e3cdc8da3965403510bf526edd5178c6 (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
/* failtest with valgrind caught this read-after-free. */
#include <ccan/talloc/talloc.c>
#include <stdbool.h>
#include <ccan/tap/tap.h>

int main(int argc, char *argv[])
{
	void *root, *p1;

	plan_tests(2);
	talloc_enable_null_tracking();
	root = talloc_new(NULL);
	p1 = talloc_strdup(root, "foo");
	talloc_increase_ref_count(p1);
	talloc_free(root);
	ok1(strcmp(p1, "foo") == 0);
	talloc_unlink(NULL, p1);

	/* This closes the leak, but make sure we're not freeing unexpected. */
	ok1(!talloc_chunk_from_ptr(null_context)->child);
	talloc_disable_null_tracking();

	return exit_status();
}