builtin/mv duplicate string list memory

makes the next patch easier, where we will migrate to the paths being owned by a strvec. given that we are talking about command line parameters here it's also not like we have tons of allocations that this would save while at it, fix a memory leak Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed May 27, 2024 at 13:47 UTC 9fcd9e4e72ff2ef2b96379d8caf03429fea279eb
1 file changed +13 -6
builtin/mv.c
+13 -6
@@ -183,11 +183,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
183 struct strbuf a_src_dir = STRBUF_INIT;
184 enum update_mode *modes, dst_mode = 0;
185 struct stat st, dest_st;
186 - struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
186 + struct string_list src_for_dst = STRING_LIST_INIT_DUP;
187 struct lock_file lock_file = LOCK_INIT;
188 struct cache_entry *ce;
189 - struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
190 - struct string_list dirty_paths = STRING_LIST_INIT_NODUP;
189 + struct string_list only_match_skip_worktree = STRING_LIST_INIT_DUP;
190 + struct string_list dirty_paths = STRING_LIST_INIT_DUP;
191 + int ret;
192
193 git_config(git_default_config, NULL);
194
@@ -440,8 +441,10 @@ remove_entry:
441
442 if (only_match_skip_worktree.nr) {
443 advise_on_updating_sparse_paths(&only_match_skip_worktree);
443 - if (!ignore_errors)
444 - return 1;
444 + if (!ignore_errors) {
445 + ret = 1;
446 + goto out;
447 + }
448 }
449
450 for (i = 0; i < argc; i++) {
@@ -566,12 +569,16 @@ remove_entry:
569 COMMIT_LOCK | SKIP_IF_UNCHANGED))
570 die(_("Unable to write new index file"));
571
572 + ret = 0;
573 +
574 +out:
575 free(dst_w_slash);
576 string_list_clear(&src_for_dst, 0);
577 string_list_clear(&dirty_paths, 0);
578 + string_list_clear(&only_match_skip_worktree, 0);
579 UNLEAK(source);
580 UNLEAK(dest_path);
581 free(submodule_gitfile);
582 free(modes);
576 - return 0;
583 + return ret;
584 }