run-corruption1.c 592 B

123456789101112131415161718192021222324
  1. /* failtest with valgrind caught this read-after-free. */
  2. #include <ccan/talloc/talloc.c>
  3. #include <stdbool.h>
  4. #include <ccan/tap/tap.h>
  5. int main(int argc, char *argv[])
  6. {
  7. void *root, *p1;
  8. plan_tests(2);
  9. talloc_enable_null_tracking();
  10. root = talloc_new(NULL);
  11. p1 = talloc_strdup(root, "foo");
  12. talloc_increase_ref_count(p1);
  13. talloc_free(root);
  14. ok1(strcmp(p1, "foo") == 0);
  15. talloc_unlink(NULL, p1);
  16. /* This closes the leak, but make sure we're not freeing unexpected. */
  17. ok1(!talloc_chunk_from_ptr(null_context)->child);
  18. talloc_disable_null_tracking();
  19. return exit_status();
  20. }