]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb: Add a talloc context to the internal data structure
authorAndreas Schneider <asn@samba.org>
Thu, 30 Oct 2025 09:56:43 +0000 (10:56 +0100)
committerAnoop C S <anoopcs@samba.org>
Thu, 6 Nov 2025 08:56:31 +0000 (08:56 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/include/libsmb_internal.h
source3/libsmb/libsmb_context.c

index bacd5a5cc628c0901f6c60eaf2472416f5b90021..5dc1808ff0d1375c28cd3542c489370995a7a458 100644 (file)
@@ -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 */
index 42082a0d94b532bf7b883dd590e087a4357fbec6..a670492867fe3ba2d6d4a0a1704847703438e423 100644 (file)
@@ -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;