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>
This commit is contained in:
parent
480a0e30a7
commit
e72e12cc02
@ -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;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='RCS merge replacement: merge-file'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
Loading…
Reference in New Issue
Block a user