void *root, *p1, *p2, *p3, *ref, *r1;
printf("test: ref_free_self\n# SINGLE REFERENCE FREE SELF FREE\n");
- talloc_erase_no_owner_context();
root = talloc_named_const(NULL, 0, "root");
p1 = talloc_named_const(root, 1, "p1");
/* r1 should have ref reference to p2 still */
talloc_report_full(NULL, stderr);
CHECK_BLOCKS(__FUNCTION__, r1, 2);
+ CHECK_BLOCKS(__FUNCTION__, p3, 1);
- /* if we talloc_steal p2 to p3, r1 should still have a reference
- (unless it had been made the parent like in old talloc */
+ /* if we talloc_steal p2 to p3, we should get an abort() */
fprintf(stderr, "Steal p2 to p3\n");
+ test_abort_start();
talloc_steal(p3, p2);
+ torture_assert(__FUNCTION__,
+ test_abort_count == 1,
+ "talloc_steal() didn't abort");
+ test_abort_stop();
+
+ talloc_report_full(NULL, stderr);
+ CHECK_BLOCKS(__FUNCTION__, r1, 2);
+ CHECK_BLOCKS(__FUNCTION__, p3, 1);
+
+ /* but we can reference p2 to p3 */
+ fprintf(stderr, "Steal p2 to p3\n");
+ talloc_reference(p3, p2);
+
talloc_report_full(NULL, stderr);
- //CHECK_BLOCKS(__FUNCTION__, r1, 2);
+ CHECK_BLOCKS(__FUNCTION__, r1, 2);
+ CHECK_BLOCKS(__FUNCTION__, p3, 2);
/* now we free p3 and r1 should still have a reference */
fprintf(stderr, "free p3\n");
talloc_free(r1);
talloc_report_full(NULL, stderr);
+ CHECK_BLOCKS(__FUNCTION__, NULL, 3);
CHECK_BLOCKS(__FUNCTION__, root, 1);
talloc_free(root);
+ CHECK_BLOCKS(__FUNCTION__, NULL, 2);
printf("success: ref1\n");
return true;
}