]> git.99rst.org Git - git.git/commit
worktree: fix resource leaks when branch creation fails
authorJohannes Schindelin <redacted>
Sun, 5 Jul 2026 08:24:25 +0000 (08:24 +0000)
committerJunio C Hamano <redacted>
Sun, 5 Jul 2026 16:12:10 +0000 (09:12 -0700)
commitda2211be7461762a47b67449cc3a518b8942ec84
tree1b72405e4a46d01531a5d32b9a6d245504e19e43
parentadd15d11ac1d882fe1a36e3f7a936fb92943ecca
worktree: fix resource leaks when branch creation fails

In the "add" subcommand, when `run_command()` fails while creating a new
branch (line 948), the function returns -1 immediately without freeing
the allocations made earlier: path (from prefix_filename at line 858),
opt_track, branch_to_free, and new_branch_to_free.

Redirect the error return through the existing cleanup block at the end
of the function so all four allocations are properly freed.

Pointed out by Coverity.

Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <redacted>
Signed-off-by: Junio C Hamano <redacted>
builtin/worktree.c
git clone https://git.99rst.org/PROJECT