]> git.ipfire.org Git - thirdparty/git.git/commit
mv: move src_dir cleanup to end of cmd_mv()
authorJeff King <peff@peff.net>
Thu, 30 May 2024 06:44:22 +0000 (02:44 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 May 2024 15:55:29 +0000 (08:55 -0700)
commitcc65e085e413c7b837e46169ff543c6c8bfcae1f
treef3ec9a0b12c100b6ac03c88e189a7c61a62bfa45
parent34eb843721bb3cd54e5fd1689d8f62bbba619bd9
mv: move src_dir cleanup to end of cmd_mv()

Commit b6f51e3db9 (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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c