diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2022-07-01 13:42:56 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-01 21:43:43 +0300 |
commit | e72e12cc02d80e4ebf01e0a3d170617211ae7c70 (patch) | |
tree | fd3159ad8ebe26def9f0a2d564b239024089a1f4 /builtin/merge-file.c | |
parent | 480a0e30a78a6a86e1ea97059f72e4bf4299d052 (diff) |
merge-file: fix memory leaks on error path
Fix a memory leak in "merge-file", we need to loop over the "mmfs"
array and free() what we've got so far when we error out. As a result
we can mark a test as passing with SANITIZE=leak using
"TEST_PASSES_SANITIZE_LEAK=true".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge-file.c')
-rw-r--r-- | builtin/merge-file.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/builtin/merge-file.c b/builtin/merge-file.c index 793817f3cb..c923bbf2ab 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -87,7 +87,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) free(fname); if (ret) - return ret; + goto cleanup; + } xmp.ancestor = names[1]; @@ -95,9 +96,6 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) xmp.file2 = names[2]; ret = xdl_merge(mmfs + 1, mmfs + 0, mmfs + 2, &xmp, &result); - for (i = 0; i < 3; i++) - free(mmfs[i].ptr); - if (ret >= 0) { const char *filename = argv[0]; char *fpath = prefix_filename(prefix, argv[0]); @@ -118,5 +116,9 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) if (ret > 127) ret = 127; +cleanup: + for (i = 0; i < 3; i++) + free(mmfs[i].ptr); + return ret; } |