]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify rename_internals_fsp()
authorVolker Lendecke <vl@samba.org>
Thu, 18 Sep 2025 19:50:57 +0000 (12:50 -0700)
committerRalph Boehme <slow@samba.org>
Tue, 21 Oct 2025 17:33:29 +0000 (17:33 +0000)
Use a new talloc_stackframe to simplify cleanup. I hope Coverity gets
this.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/smb2_reply.c

index cf7830e3912a3fd9e2676c5e0da38bae351da416..9808fcc2ab14eb4d370e78ac110e76e02208b017 100644 (file)
@@ -1358,7 +1358,7 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
                              const char *newname,
                              bool replace_if_exists)
 {
-       TALLOC_CTX *ctx = talloc_tos();
+       TALLOC_CTX *ctx = talloc_stackframe();
        struct smb_filename *parent_dir_fname_dst = NULL;
        struct smb_filename *parent_dir_fname_dst_atname = NULL;
        struct smb_filename *parent_dir_fname_src = NULL;
@@ -1375,7 +1375,8 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
        struct vfs_rename_how rhow = { .flags = 0, };
 
        if (file_has_open_streams(fsp)) {
-               return NT_STATUS_ACCESS_DENIED;
+               status = NT_STATUS_ACCESS_DENIED;
+               goto out;
        }
 
        /* Make a copy of the dst smb_fname structs */
@@ -1773,18 +1774,7 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
                   smb_fname_str_dbg(smb_fname_dst));
 
  out:
-
-       /*
-        * parent_dir_fname_src may be a copy of parent_dir_fname_dst.
-        * See the optimization for same source and destination directory
-        * above. Only free one in that case.
-        */
-       if (parent_dir_fname_src != parent_dir_fname_dst) {
-               TALLOC_FREE(parent_dir_fname_src);
-       }
-       TALLOC_FREE(parent_dir_fname_dst);
-       TALLOC_FREE(smb_fname_dst);
-
+       TALLOC_FREE(ctx);
        return status;
 }