]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
source3/printing: Fix CID 1273086 - Resource Leak
authorShwetha K Acharya <Shwetha.K.Acharya@ibm.com>
Thu, 31 Jul 2025 12:59:05 +0000 (18:29 +0530)
committerAnoop C S <anoopcs@samba.org>
Tue, 5 Aug 2025 09:20:17 +0000 (09:20 +0000)
Ensure print_queue_struct *q is initialized to NULL to avoid
undefined behavior when freeing on error paths. Move SAFE_FREE(q)
outside the ret > 0 block to ensure q is always freed.

Signed-off-by: Shwetha K Acharya <Shwetha.K.Acharya@ibm.com>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Vinit Agnihotri <vagnihot@redhat.com>
Autobuild-User(master): Anoop C S <anoopcs@samba.org>
Autobuild-Date(master): Tue Aug  5 09:20:17 UTC 2025 on atb-devel-224

source3/printing/print_generic.c

index a8bf9aff972527fb6337c6c139ffde5df68b4efe..d5bfa9ea52764e89e5dd5087d19101020d23e213 100644 (file)
@@ -225,7 +225,7 @@ static int generic_job_submit(int snum, struct printjob *pjob,
        char *jobname = NULL;
        TALLOC_CTX *ctx = talloc_tos();
        fstring job_page_count, job_size;
-       print_queue_struct *q;
+       print_queue_struct *q = NULL;
        print_status_struct status;
 
        /* we print from the directory path to give the best chance of
@@ -299,7 +299,6 @@ static int generic_job_submit(int snum, struct printjob *pjob,
                                break;
                        }
                }
-               SAFE_FREE(q);
                ret = 0;
        }
        if (pjob->sysjob == -1) {
@@ -313,6 +312,7 @@ static int generic_job_submit(int snum, struct printjob *pjob,
        if (chdir(current_directory) == -1) {
                smb_panic("chdir failed in generic_job_submit");
        }
+       SAFE_FREE(q);
        TALLOC_FREE(current_directory);
         return ret;
 }