Skip to content

Commit bc57ba1

Browse files
avargitster
authored andcommitted
submodule.c: free() memory from xgetcwd()
Fix a memory leak in code added in bf0231c (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 74a06a9 commit bc57ba1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

submodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,7 @@ int get_superproject_working_tree(struct strbuf *buf)
23882388
struct child_process cp = CHILD_PROCESS_INIT;
23892389
struct strbuf sb = STRBUF_INIT;
23902390
struct strbuf one_up = STRBUF_INIT;
2391-
const char *cwd = xgetcwd();
2391+
char *cwd = xgetcwd();
23922392
int ret = 0;
23932393
const char *subpath;
23942394
int code;
@@ -2451,6 +2451,7 @@ int get_superproject_working_tree(struct strbuf *buf)
24512451
ret = 1;
24522452
free(super_wt);
24532453
}
2454+
free(cwd);
24542455
strbuf_release(&sb);
24552456

24562457
code = finish_command(&cp);

0 commit comments

Comments
 (0)