Skip to content

Commit 9fcd9e4

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d231f7 commit 9fcd9e4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

builtin/mv.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
183183
struct strbuf a_src_dir = STRBUF_INIT;
184184
enum update_mode *modes, dst_mode = 0;
185185
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;
187187
struct lock_file lock_file = LOCK_INIT;
188188
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;
191192

192193
git_config(git_default_config, NULL);
193194

@@ -440,8 +441,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
440441

441442
if (only_match_skip_worktree.nr) {
442443
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+
}
445448
}
446449

447450
for (i = 0; i < argc; i++) {
@@ -566,12 +569,16 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
566569
COMMIT_LOCK | SKIP_IF_UNCHANGED))
567570
die(_("Unable to write new index file"));
568571

572+
ret = 0;
573+
574+
out:
569575
free(dst_w_slash);
570576
string_list_clear(&src_for_dst, 0);
571577
string_list_clear(&dirty_paths, 0);
578+
string_list_clear(&only_match_skip_worktree, 0);
572579
UNLEAK(source);
573580
UNLEAK(dest_path);
574581
free(submodule_gitfile);
575582
free(modes);
576-
return 0;
583+
return ret;
577584
}

0 commit comments

Comments
 (0)