Skip to content

Commit ece3974

Browse files
avargitster
authored andcommitted
pull: fix a "struct oid_array" memory leak
Fix a memory leak introduced in 44c175c (pull: error on no merge candidates, 2015-06-18). As a result we can mark several tests as passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true". Removing the "int ret = 0" assignment added here in a6d7eb2 (pull: optionally rebase submodules (remote submodule changes only), 2017-06-23) is not a logic error, it could always have been left uninitialized (as "int ret"), now that we'll use the "ret" from the upper scope we can drop the assignment in the "opt_rebase" branch. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27472b5 commit ece3974

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

builtin/pull.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
990990
int rebase_unspecified = 0;
991991
int can_ff;
992992
int divergent;
993+
int ret;
993994

994995
if (!getenv("GIT_REFLOG_ACTION"))
995996
set_reflog_message(argc, argv);
@@ -1100,7 +1101,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
11001101
if (is_null_oid(&orig_head)) {
11011102
if (merge_heads.nr > 1)
11021103
die(_("Cannot merge multiple branches into empty head."));
1103-
return pull_into_void(merge_heads.oid, &curr_head);
1104+
ret = pull_into_void(merge_heads.oid, &curr_head);
1105+
goto cleanup;
11041106
}
11051107
if (merge_heads.nr > 1) {
11061108
if (opt_rebase)
@@ -1125,8 +1127,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
11251127
}
11261128

11271129
if (opt_rebase) {
1128-
int ret = 0;
1129-
11301130
struct object_id newbase;
11311131
struct object_id upstream;
11321132
get_rebase_newbase_and_upstream(&newbase, &upstream, &curr_head,
@@ -1149,12 +1149,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
11491149
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))
11501150
ret = rebase_submodules();
11511151

1152-
return ret;
1152+
goto cleanup;
11531153
} else {
1154-
int ret = run_merge();
1154+
ret = run_merge();
11551155
if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
11561156
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))
11571157
ret = update_submodules();
1158-
return ret;
1158+
goto cleanup;
11591159
}
1160+
1161+
cleanup:
1162+
oid_array_clear(&merge_heads);
1163+
return ret;
11601164
}

t/t5524-pull-msg.sh

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

33
test_description='git pull message generation'
44

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

78
dollar='$Dollar'

t/t6417-merge-ours-theirs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='Merge-recursive ours and theirs variants'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
test_expect_success setup '

t/t9101-git-svn-props.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
test_description='git svn property tests'
77

8-
TEST_FAILS_SANITIZE_LEAK=true
98
. ./lib-git-svn.sh
109

1110
mkdir import

0 commit comments

Comments
 (0)