Skip to content

Commit 58f4661

Browse files
committed
submodule: fix cwd leak in get_superproject_working_tree()
get_superproject_working_tree() allocates cwd via xgetcwd() at the top of the function, but two early-return paths (when not inside a work tree, and when strbuf_realpath for "../" fails) return 0 without freeing it. Redirect these early returns through a cleanup label that frees cwd before returning. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 48598aa commit 58f4661

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

submodule.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,10 +2626,10 @@ int get_superproject_working_tree(struct strbuf *buf)
26262626
* We might have a superproject, but it is harder
26272627
* to determine.
26282628
*/
2629-
return 0;
2629+
goto out;
26302630

26312631
if (!strbuf_realpath(&one_up, "../", 0))
2632-
return 0;
2632+
goto out;
26332633

26342634
subpath = relative_path(cwd, one_up.buf, &sb);
26352635
strbuf_release(&one_up);
@@ -2692,6 +2692,10 @@ int get_superproject_working_tree(struct strbuf *buf)
26922692
die(_("ls-tree returned unexpected return code %d"), code);
26932693

26942694
return ret;
2695+
2696+
out:
2697+
free(cwd);
2698+
return 0;
26952699
}
26962700

26972701
/*

0 commit comments

Comments
 (0)