]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/torture: give torture_context_child() a dedicated talloc parent and avoid talloc_...
authorStefan Metzmacher <metze@samba.org>
Fri, 9 May 2025 09:18:18 +0000 (11:18 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 19 May 2025 09:11:29 +0000 (09:11 +0000)
The caller should manage the liftimes.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/torture/torture.c
lib/torture/torture.h

index 14adf7c570da5f861234ff51d3e6e0237bb07261..0a5dcd30ec449a3ff3162afa05b064d87210007e 100644 (file)
@@ -81,17 +81,33 @@ struct torture_context *torture_context_init(TALLOC_CTX *mem_ctx,
 /**
  * Create a sub torture context
  */
-struct torture_context *torture_context_child(struct torture_context *parent)
+struct torture_context *torture_context_child(TALLOC_CTX *mem_ctx,
+                                             struct torture_context *parent)
 {
-       struct torture_context *subtorture = talloc_zero(parent, struct torture_context);
+       struct torture_context *subtorture = NULL;
 
-       if (subtorture == NULL)
+       SMB_ASSERT(parent);
+       SMB_ASSERT(parent->ev);
+       SMB_ASSERT(parent->lp_ctx);
+       SMB_ASSERT(parent->results);
+       SMB_ASSERT(parent->outputdir);
+
+       subtorture = talloc_zero(mem_ctx, struct torture_context);
+       if (subtorture == NULL) {
                return NULL;
+       }
 
-       subtorture->ev = talloc_reference(subtorture, parent->ev);
-       subtorture->lp_ctx = talloc_reference(subtorture, parent->lp_ctx);
-       subtorture->outputdir = talloc_reference(subtorture, parent->outputdir);
-       subtorture->results = talloc_reference(subtorture, parent->results);
+       subtorture->ev = parent->ev;
+       subtorture->lp_ctx = parent->lp_ctx;
+       subtorture->results = parent->results;
+       subtorture->outputdir = parent->outputdir;
+
+       if (parent->active_prefix != NULL) {
+               memcpy(subtorture->_initial_prefix.subunit_prefix,
+                      parent->active_prefix->subunit_prefix,
+                      sizeof(subtorture->active_prefix->subunit_prefix));
+       }
+       subtorture->active_prefix = &subtorture->_initial_prefix;
 
        return subtorture;
 }
index 63124e8392904bcbd85bc368cbcaa447afd7ccb7..8c8fa32634547214a70b07ce1ff4054a2e694d03 100644 (file)
@@ -916,7 +916,8 @@ struct torture_context *torture_context_init(TALLOC_CTX *mem_ctx,
 
 struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops);
 
-struct torture_context *torture_context_child(struct torture_context *tctx);
+struct torture_context *torture_context_child(TALLOC_CTX *mem_ctx,
+                                             struct torture_context *parent);
 
 extern const struct torture_ui_ops torture_subunit_ui_ops;
 extern const struct torture_ui_ops torture_simple_ui_ops;