Skip to content

Commit 90428dd

Browse files
avargitster
authored andcommitted
repack: fix leaks on error with "goto cleanup"
In cmd_repack() when we hit an error, replace "return ret" with "goto cleanup" to ensure we free the necessary data structures. Helped-by: Elijah Newren <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 486620a commit 90428dd

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

builtin/repack.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
948948

949949
ret = start_command(&cmd);
950950
if (ret)
951-
return ret;
951+
goto cleanup;
952952

953953
if (geometry) {
954954
FILE *in = xfdopen(cmd.in, "w");
@@ -977,7 +977,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
977977
fclose(out);
978978
ret = finish_command(&cmd);
979979
if (ret)
980-
return ret;
980+
goto cleanup;
981981

982982
if (!names.nr && !po_args.quiet)
983983
printf_ln(_("Nothing new to pack."));
@@ -1007,7 +1007,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
10071007
&existing_nonkept_packs,
10081008
&existing_kept_packs);
10091009
if (ret)
1010-
return ret;
1010+
goto cleanup;
10111011

10121012
if (delete_redundant && expire_to) {
10131013
/*
@@ -1039,7 +1039,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
10391039
&existing_nonkept_packs,
10401040
&existing_kept_packs);
10411041
if (ret)
1042-
return ret;
1042+
goto cleanup;
10431043
}
10441044
}
10451045

@@ -1115,7 +1115,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
11151115
string_list_clear(&include, 0);
11161116

11171117
if (ret)
1118-
return ret;
1118+
goto cleanup;
11191119
}
11201120

11211121
reprepare_packed_git(the_repository);
@@ -1172,10 +1172,11 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
11721172
write_midx_file(get_object_directory(), NULL, NULL, flags);
11731173
}
11741174

1175+
cleanup:
11751176
string_list_clear(&names, 1);
11761177
string_list_clear(&existing_nonkept_packs, 0);
11771178
string_list_clear(&existing_kept_packs, 0);
11781179
clear_pack_geometry(geometry);
11791180

1180-
return 0;
1181+
return ret;
11811182
}

t/t5312-prune-corruption.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ what currently happens. If that changes, these tests should be revisited.
1414
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1515
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1616

17+
TEST_PASSES_SANITIZE_LEAK=true
1718
. ./test-lib.sh
1819

1920
test_expect_success 'disable reflogs' '

t/t6011-rev-list-with-bad-commit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git rev-list should notice bad commits'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
# Note:

0 commit comments

Comments
 (0)