From: Stefan Metzmacher Date: Fri, 9 May 2025 09:18:18 +0000 (+0200) Subject: lib/torture: give torture_context_child() a dedicated talloc parent and avoid talloc_... X-Git-Tag: tevent-0.17.0~147 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17f815644b3c6d7e7be2964eee1ab7fc67a357d9;p=thirdparty%2Fsamba.git lib/torture: give torture_context_child() a dedicated talloc parent and avoid talloc_reference The caller should manage the liftimes. Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- diff --git a/lib/torture/torture.c b/lib/torture/torture.c index 14adf7c570d..0a5dcd30ec4 100644 --- a/lib/torture/torture.c +++ b/lib/torture/torture.c @@ -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; } diff --git a/lib/torture/torture.h b/lib/torture/torture.h index 63124e83929..8c8fa326345 100644 --- a/lib/torture/torture.h +++ b/lib/torture/torture.h @@ -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;