]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_recycle: directly allocate smb_fname_final->base_name
authorStefan Metzmacher <metze@samba.org>
Fri, 14 Jun 2024 08:07:02 +0000 (10:07 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 19 Jun 2024 09:07:36 +0000 (09:07 +0000)
We can use talloc_asprintf() instead of asprintf() followed
by talloc_strdup().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15659

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Noel Power <noel.power@suse.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/modules/vfs_recycle.c

index 47b21983984fec8f00906900e227905ea4460582..e8c33c3585cf379a0860b1895dd9f6adcb9d0ab2 100644 (file)
@@ -643,14 +643,16 @@ static int recycle_unlink_internal(vfs_handle_struct *handle,
        /* rename file we move to recycle bin */
        i = 1;
        while (recycle_file_exist(handle, smb_fname_final)) {
-               SAFE_FREE(final_name);
-               if (asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base) == -1) {
-                       ALLOC_CHECK(final_name, done);
-               }
+               char *copy = NULL;
+
                TALLOC_FREE(smb_fname_final->base_name);
-               smb_fname_final->base_name = talloc_strdup(smb_fname_final,
-                                                          final_name);
-               ALLOC_CHECK(smb_fname_final->base_name, done);
+               copy = talloc_asprintf(smb_fname_final, "%s/Copy #%d of %s",
+                                      temp_name, i++, base);
+               if (copy == NULL) {
+                       rc = -1;
+                       goto done;
+               }
+               smb_fname_final->base_name = copy;
        }
 
        DEBUG(10, ("recycle: Moving %s to %s\n", smb_fname_str_dbg(full_fname),