From: Stefan Metzmacher Date: Fri, 14 Jun 2024 08:07:02 +0000 (+0200) Subject: vfs_recycle: directly allocate smb_fname_final->base_name X-Git-Tag: tdb-1.4.11~345 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=220b0e977e2e25f2033cfd62c17d998c750992fc;p=thirdparty%2Fsamba.git vfs_recycle: directly allocate smb_fname_final->base_name 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 Reviewed-by: Martin Schwenke Reviewed-by: Noel Power Reviewed-by: Volker Lendecke --- diff --git a/source3/modules/vfs_recycle.c b/source3/modules/vfs_recycle.c index 47b21983984..e8c33c3585c 100644 --- a/source3/modules/vfs_recycle.c +++ b/source3/modules/vfs_recycle.c @@ -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),