s4:torture:smb2: fix a nasty double free error.
authorMichael Adam <obnox@samba.org>
Thu, 27 Oct 2011 22:05:44 +0000 (00:05 +0200)
committerMichael Adam <obnox@samba.org>
Thu, 27 Oct 2011 23:00:01 +0000 (01:00 +0200)
This error manifested itself in sporadic "talloc_free with references" error.

source4/torture/smb2/smb2.c

index 35a987e927c2bb193eeebeac33e9bab8519c6a8b..3bbad29d6b4d3f8d388d0ce28f5c045cd1f0ddb2 100644 (file)
@@ -30,17 +30,25 @@ static bool wrap_simple_1smb2_test(struct torture_context *torture_ctx,
 {
        bool (*fn) (struct torture_context *, struct smb2_tree *);
        bool ret;
-
        struct smb2_tree *tree1;
+       TALLOC_CTX *mem_ctx = talloc_new(torture_ctx);
 
        if (!torture_smb2_connection(torture_ctx, &tree1))
                return false;
 
+       /*
+        * This is a trick:
+        * The test might close the connection. If we steal the tree context
+        * before that and free the parent instead of tree directly, we avoid
+        * a double free error.
+        */
+       talloc_steal(mem_ctx, tree1);
+
        fn = test->fn;
 
        ret = fn(torture_ctx, tree1);
 
-       talloc_free(tree1);
+       talloc_free(mem_ctx);
 
        return ret;
 }