From 959ea545fbd899dba14dc1216b8f4dca8cdb9b52 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 30 Oct 2025 10:56:43 +0100 Subject: [PATCH] s3:libsmb: Add a talloc context to the internal data structure Signed-off-by: Andreas Schneider Reviewed-by: Anoop C S --- source3/include/libsmb_internal.h | 2 ++ source3/libsmb/libsmb_context.c | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h index bacd5a5cc62..5dc1808ff0d 100644 --- a/source3/include/libsmb_internal.h +++ b/source3/include/libsmb_internal.h @@ -263,6 +263,8 @@ struct SMBC_internal_data { uint16_t port; struct loadparm_context *lp_ctx; + + TALLOC_CTX *mem_ctx; }; /* Functions in libsmb_cache.c */ diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c index 42082a0d94b..a670492867f 100644 --- a/source3/libsmb/libsmb_context.c +++ b/source3/libsmb/libsmb_context.c @@ -173,9 +173,18 @@ smbc_new_context(void) return NULL; } - context->internal->lp_ctx = loadparm_init_s3(NULL, + context->internal->mem_ctx = talloc_new(NULL); + if (context->internal->mem_ctx == NULL) { + SAFE_FREE(context->internal); + SAFE_FREE(context); + TALLOC_FREE(frame); + return NULL; + } + + context->internal->lp_ctx = loadparm_init_s3(context->internal->mem_ctx, loadparm_s3_helpers()); if (context->internal->lp_ctx == NULL) { + TALLOC_FREE(context->internal->mem_ctx); SAFE_FREE(context->internal); SAFE_FREE(context); TALLOC_FREE(frame); @@ -335,15 +344,12 @@ smbc_free_context(SMBCCTX *context, smbc_setNetbiosName(context, NULL); smbc_setUser(context, NULL); - DEBUG(3, ("Context %p successfully freed\n", context)); - - /* Free any DFS auth context. */ - TALLOC_FREE(context->internal->creds); - - TALLOC_FREE(context->internal->lp_ctx); + TALLOC_FREE(context->internal->mem_ctx); SAFE_FREE(context->internal); SAFE_FREE(context); + DEBUG(3, ("Context %p successfully freed\n", context)); + /* Protect access to the count of contexts in use */ if (SMB_THREAD_LOCK(initialized_ctx_count_mutex) != 0) { smb_panic("error locking 'initialized_ctx_count'"); @@ -775,7 +781,7 @@ void smbc_set_credentials_with_fallback(SMBCCTX *context, password = ""; } - creds = cli_credentials_init(NULL); + creds = cli_credentials_init(context->internal->mem_ctx); if (creds == NULL) { DEBUG(0, ("smbc_set_credentials_with_fallback: allocation fail\n")); return; -- 2.47.3