diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2022-07-01 12:42:52 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-01 20:43:42 +0200 |
commit | bc57ba1d54f3133cd46481532d97a8346b62d8aa (patch) | |
tree | 82ee691699da80364b176244fb3c1dc42cf6e647 /submodule.c | |
parent | clone: fix memory leak in wanted_peer_refs() (diff) | |
download | git-bc57ba1d54f3133cd46481532d97a8346b62d8aa.tar.xz git-bc57ba1d54f3133cd46481532d97a8346b62d8aa.zip |
submodule.c: free() memory from xgetcwd()
Fix a memory leak in code added in bf0231c6614 (rev-parse: add
--show-superproject-working-tree, 2017-03-08), we should never have
made the result of xgetcwd() a "const char *", as we return a
strbuf_detach()'d value. Let's fix that and free() it when we're done
with it.
We can't mark any tests passing passing with SANITIZE=leak using
"TEST_PASSES_SANITIZE_LEAK=true" as a result of this change, but
e.g. "t/t1500-rev-parse.sh" now gets closer to passing.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r-- | submodule.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/submodule.c b/submodule.c index 4e299f578f..06073b2e7b 100644 --- a/submodule.c +++ b/submodule.c @@ -2388,7 +2388,7 @@ int get_superproject_working_tree(struct strbuf *buf) struct child_process cp = CHILD_PROCESS_INIT; struct strbuf sb = STRBUF_INIT; struct strbuf one_up = STRBUF_INIT; - const char *cwd = xgetcwd(); + char *cwd = xgetcwd(); int ret = 0; const char *subpath; int code; @@ -2451,6 +2451,7 @@ int get_superproject_working_tree(struct strbuf *buf) ret = 1; free(super_wt); } + free(cwd); strbuf_release(&sb); code = finish_command(&cp); |