Skip to content

Commit cc65e08

Browse files
peffgitster
authored andcommitted
mv: move src_dir cleanup to end of cmd_mv()
Commit b6f51e3 (mv: cleanup empty WORKING_DIRECTORY, 2022-08-09) added an auxiliary array where we store directory arguments that we see while processing the incoming arguments. After actually moving things, we then use that array to remove now-empty directories, and then immediately free the array. But if the actual move queues any errors in only_match_skip_worktree, that can cause us to jump straight to the "out" label to clean up, skipping the free() and leaking the array. Let's push the free() down past the "out" label so that we always clean up (the array is initialized to NULL, so this is always safe). We'll hold on to the memory a little longer than necessary, but clarity is more important than micro-optimizing here. Note that the adjacent "a_src_dir" strbuf does not suffer the same problem; it is only allocated during the removal step. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 34eb843 commit cc65e08

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
556556
}
557557

558558
strbuf_release(&a_src_dir);
559-
free(src_dir);
560559

561560
if (dirty_paths.nr)
562561
advise_on_moving_dirty_path(&dirty_paths);
@@ -571,6 +570,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
571570
ret = 0;
572571

573572
out:
573+
free(src_dir);
574574
free(dst_w_slash);
575575
string_list_clear(&src_for_dst, 0);
576576
string_list_clear(&dirty_paths, 0);

0 commit comments

Comments
 (0)