s3:smbd: split out a fsp_attach_smb_fname() helper function
authorStefan Metzmacher <metze@samba.org>
Wed, 16 Dec 2020 14:01:38 +0000 (15:01 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 14 Jan 2021 11:30:38 +0000 (11:30 +0000)
It's useful to watch this using: git show --histogram

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

index 446cbec52513ff0cdd76253c70cddc13aa7f14d7..70e128a3c5c466f2bf60e5791f01bfbba7742a09 100644 (file)
@@ -1229,26 +1229,16 @@ NTSTATUS file_name_hash(connection_struct *conn,
        return NT_STATUS_OK;
 }
 
-/**
- * The only way that the fsp->fsp_name field should ever be set.
- */
-NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
-                          const struct smb_filename *smb_fname_in)
+static NTSTATUS fsp_attach_smb_fname(struct files_struct *fsp,
+                                    struct smb_filename **_smb_fname)
 {
-       struct smb_filename *smb_fname_old = fsp->fsp_name;
-       struct smb_filename *smb_fname_new = NULL;
+       struct smb_filename *smb_fname_new = *_smb_fname;
        const char *name_str = NULL;
        uint32_t name_hash = 0;
        NTSTATUS status;
 
-       smb_fname_new = cp_smb_filename(fsp, smb_fname_in);
-       if (smb_fname_new == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
        name_str = smb_fname_str_dbg(smb_fname_new);
        if (name_str == NULL) {
-               TALLOC_FREE(smb_fname_new);
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -1256,7 +1246,6 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
                                name_str,
                                &name_hash);
        if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(smb_fname_new);
                return status;
        }
 
@@ -1264,12 +1253,35 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
                                    &smb_fname_new->fsp_link,
                                    &smb_fname_new->fsp);
        if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(smb_fname_new);
                return status;
        }
 
        fsp->name_hash = name_hash;
        fsp->fsp_name = smb_fname_new;
+       *_smb_fname = NULL;
+       return NT_STATUS_OK;
+}
+
+/**
+ * The only way that the fsp->fsp_name field should ever be set.
+ */
+NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
+                          const struct smb_filename *smb_fname_in)
+{
+       struct smb_filename *smb_fname_old = fsp->fsp_name;
+       struct smb_filename *smb_fname_new = NULL;
+       NTSTATUS status;
+
+       smb_fname_new = cp_smb_filename(fsp, smb_fname_in);
+       if (smb_fname_new == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = fsp_attach_smb_fname(fsp, &smb_fname_new);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(smb_fname_new);
+               return status;
+       }
 
        if (smb_fname_old != NULL) {
                smb_fname_fsp_unlink(smb_fname_old);