X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftalloc%2Ftest%2Frun-corruption1.c;fp=ccan%2Ftalloc%2Ftest%2Frun-corruption1.c;h=d6ac7da5e3cdc8da3965403510bf526edd5178c6;hb=87aba1fa2abc28ff06f82e30cde3fa3d991e8e18;hp=0000000000000000000000000000000000000000;hpb=f0002cb9e4f6f403a25ad50252c06694439900f0;p=ccan diff --git a/ccan/talloc/test/run-corruption1.c b/ccan/talloc/test/run-corruption1.c new file mode 100644 index 00000000..d6ac7da5 --- /dev/null +++ b/ccan/talloc/test/run-corruption1.c @@ -0,0 +1,24 @@ +/* failtest with valgrind caught this read-after-free. */ +#include +#include +#include + +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(); +}