summaryrefslogtreecommitdiff
path: root/lib/talloc/testsuite.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-04-20 15:30:57 +1000
committerAndrew Tridgell <tridge@samba.org>2010-04-20 15:50:27 +1000
commit45be1c7ba4382d85c742a241687bbc6d5a2ebd8c (patch)
treec9fabbf2b9566bad59f7d87d7461d7cff78396fa /lib/talloc/testsuite.c
parent773a8afbba27a5e2e48577100f3ca9873b506615 (diff)
downloadsamba-45be1c7ba4382d85c742a241687bbc6d5a2ebd8c.tar.gz
samba-45be1c7ba4382d85c742a241687bbc6d5a2ebd8c.tar.bz2
samba-45be1c7ba4382d85c742a241687bbc6d5a2ebd8c.zip
talloc: there is no ambiguity when freeing a ptr with a null parent
when a ptr has a single reference and a NULL parent, then talloc_free(ptr) is not ambiguous, as the caller could not have done a talloc_free(NULL) to free the memory Pair-Programmed-With: Rusty Russell <rusty@samba.org>
Diffstat (limited to 'lib/talloc/testsuite.c')
-rw-r--r--lib/talloc/testsuite.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c
index f33805d6b0..5e9b3ec8f2 100644
--- a/lib/talloc/testsuite.c
+++ b/lib/talloc/testsuite.c
@@ -1132,6 +1132,37 @@ static bool test_pool(void)
return true;
}
+
+static bool test_free_ref_null_context(void)
+{
+ void *p1, *p2, *p3;
+ int ret;
+
+ talloc_disable_null_tracking();
+ p1 = talloc_new(NULL);
+ p2 = talloc_new(NULL);
+
+ p3 = talloc_reference(p2, p1);
+ torture_assert("reference", p3 == p1, "failed: reference on null");
+
+ ret = talloc_free(p1);
+ torture_assert("ref free with null parent", ret == 0, "failed: free with null parent");
+ talloc_free(p2);
+
+ talloc_enable_null_tracking_no_autofree();
+ p1 = talloc_new(NULL);
+ p2 = talloc_new(NULL);
+
+ p3 = talloc_reference(p2, p1);
+ torture_assert("reference", p3 == p1, "failed: reference on null");
+
+ ret = talloc_free(p1);
+ torture_assert("ref free with null tracked parent", ret == 0, "failed: free with null parent");
+ talloc_free(p2);
+
+ return true;
+}
+
static void test_reset(void)
{
talloc_set_log_fn(test_log_stdout);
@@ -1185,6 +1216,8 @@ bool torture_local_talloc(struct torture_context *tctx)
ret &= test_talloc_free_in_destructor();
test_reset();
ret &= test_pool();
+ test_reset();
+ ret &= test_free_ref_null_context();
if (ret) {
test_reset();