[PATCH 08/13] submodule: fix cwd leak in get_superproject_working_tree()
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Jul 1, 2026, 07:04 UTC
- Message-ID
- <6a43f952417259c23ca456c547b0e4587a0ce6fa.1782889472.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2163.git.1782889472.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
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> --- submodule.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/submodule.c b/submodule.c index fd91201a92..8ddeebd8af 100644 --- a/submodule.c +++ b/submodule.c @@ -2627,10 +2627,10 @@ int get_superproject_working_tree(struct strbuf *buf) * We might have a superproject, but it is harder * to determine. */ - return 0; + goto out; if (!strbuf_realpath(&one_up, "../", 0)) - return 0; + goto out; subpath = relative_path(cwd, one_up.buf, &sb); strbuf_release(&one_up); @@ -2693,6 +2693,10 @@ int get_superproject_working_tree(struct strbuf *buf) die(_("ls-tree returned unexpected return code %d"), code); return ret; + +out: + free(cwd); + return 0; } /*
-- gitgitgadget