]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pull: fix a "struct oid_array" memory leak
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 1 Jul 2022 10:43:00 +0000 (12:43 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2022 18:43:43 +0000 (11:43 -0700)
Fix a memory leak introduced in 44c175c7a46 (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 a6d7eb2c7a6 (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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pull.c
t/t5524-pull-msg.sh
t/t6417-merge-ours-theirs.sh
t/t9101-git-svn-props.sh

index 01155ba67b20d6593e09b239d8a5bbb3eb195535..403a24d7ca670f9a5c56ebfb6d8429b5e5817b54 100644 (file)
@@ -990,6 +990,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        int rebase_unspecified = 0;
        int can_ff;
        int divergent;
+       int ret;
 
        if (!getenv("GIT_REFLOG_ACTION"))
                set_reflog_message(argc, argv);
@@ -1100,7 +1101,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        if (is_null_oid(&orig_head)) {
                if (merge_heads.nr > 1)
                        die(_("Cannot merge multiple branches into empty head."));
-               return pull_into_void(merge_heads.oid, &curr_head);
+               ret = pull_into_void(merge_heads.oid, &curr_head);
+               goto cleanup;
        }
        if (merge_heads.nr > 1) {
                if (opt_rebase)
@@ -1125,8 +1127,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        }
 
        if (opt_rebase) {
-               int ret = 0;
-
                struct object_id newbase;
                struct object_id upstream;
                get_rebase_newbase_and_upstream(&newbase, &upstream, &curr_head,
@@ -1149,12 +1149,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                             recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))
                        ret = rebase_submodules();
 
-               return ret;
+               goto cleanup;
        } else {
-               int ret = run_merge();
+               ret = run_merge();
                if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
                             recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))
                        ret = update_submodules();
-               return ret;
+               goto cleanup;
        }
+
+cleanup:
+       oid_array_clear(&merge_heads);
+       return ret;
 }
index b2be3605f5a3f0649879a31803b5fc7cfe40d8a1..56716e29ddf1c3ded4cfae0443ee60ffe4eb0945 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='git pull message generation'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 dollar='$Dollar'
index 62d1406119e8c2b08a1a93e3d8fb95167ad16e7d..482b73a998ff2aa6651fc3fc7bd845fffd2c80c3 100755 (executable)
@@ -4,6 +4,7 @@ test_description='Merge-recursive ours and theirs variants'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success setup '
index d043e80fc349f85e1cd4168c9bf4d343dfeee0d5..52046e60d5150d0ee71bcbb515277b4bf1e6969d 100755 (executable)
@@ -5,7 +5,6 @@
 
 test_description='git svn property tests'
 
-TEST_FAILS_SANITIZE_LEAK=true
 . ./lib-git-svn.sh
 
 mkdir import