]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:client: Use talloc to avoid memory leaks in smbspool
authorAndreas Schneider <asn@samba.org>
Wed, 22 Oct 2025 09:24:24 +0000 (11:24 +0200)
committerAnoop C S <anoopcs@samba.org>
Fri, 24 Oct 2025 07:42:37 +0000 (07:42 +0000)
The function uri_unescape_alloc() is called by main() which has a talloc
stackframe.

Direct leak of 13 byte(s) in 1 object(s) allocated from:
    #0 0x7fc31351b9a0 in strdup (/lib64/libasan.so.8+0x11b9a0) (BuildId: 388ee9ac193f74c177c6f52988d2d0dab110de41)
    #1 0x7fc3129cfb50 in smb_xstrdup ../../lib/util/util.c:760
    #2 0x0000002059f8 in uri_unescape_alloc ../../source3/client/smbspool.c:888
    #3 0x00000020752a in main ../../source3/client/smbspool.c:347
    #4 0x7fc30f62b2fa in __libc_start_call_main (/lib64/libc.so.6+0x2b2fa) (BuildId: 8523b213e7586a93ab00f6dd476418b1e521e62c)
    #5 0x7ffd8bb806be  ([stack]+0x3b6be)

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Anoop C S <anoopcs@samba.org>
Autobuild-Date(master): Fri Oct 24 07:42:37 UTC 2025 on atb-devel-224

source3/client/smbspool.c

index c056cc769962a3f628de54bf49d664baa35e66b1..d524654270931ebee08fe4adbb9a8c9348fc6042 100644 (file)
@@ -883,16 +883,14 @@ smb_print(struct cli_state * cli, /* I - SMB connection */
 static char *
 uri_unescape_alloc(const char *uritok)
 {
-       char *ret;
-       char *end;
-       ret = (char *) SMB_STRDUP(uritok);
+       char *end = NULL;
+       char *ret = talloc_strdup(talloc_tos(), uritok);
        if (!ret) {
                return NULL;
        }
 
        end = rfc1738_unescape(ret);
        if (end == NULL) {
-               free(ret);
                return NULL;
        }
        return ret;