]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/merge: always store allocated strings in `pull_twohead`
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:39:35 +0000 (08:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:56 +0000 (10:30 -0700)
The `pull_twohead` configuration may sometimes contain an allocated
string, and sometimes it may contain a string constant. Refactor this to
instead always store an allocated string such that we can release its
resources without risk.

While at it, manage the lifetime of other config strings, as well. Note
that we explicitly don't free `cleanup_arg` here. This is because the
variable may be assigned a string constant via command line options.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c

index daed2d4e1e2beb5da58f4d418c2b10e63d5ad36b..fb3eb15b8955661586eeb76bc59d4532354739a9 100644 (file)
@@ -611,17 +611,19 @@ static int git_merge_config(const char *k, const char *v,
                return 0;
        }
 
-       if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
+       if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) {
                show_diffstat = git_config_bool(k, v);
-       else if (!strcmp(k, "merge.verifysignatures"))
+       } else if (!strcmp(k, "merge.verifysignatures")) {
                verify_signatures = git_config_bool(k, v);
-       else if (!strcmp(k, "pull.twohead"))
+       } else if (!strcmp(k, "pull.twohead")) {
+               FREE_AND_NULL(pull_twohead);
                return git_config_string(&pull_twohead, k, v);
-       else if (!strcmp(k, "pull.octopus"))
+       } else if (!strcmp(k, "pull.octopus")) {
+               FREE_AND_NULL(pull_octopus);
                return git_config_string(&pull_octopus, k, v);
-       else if (!strcmp(k, "commit.cleanup"))
+       } else if (!strcmp(k, "commit.cleanup")) {
                return git_config_string(&cleanup_arg, k, v);
-       else if (!strcmp(k, "merge.ff")) {
+       else if (!strcmp(k, "merge.ff")) {
                int boolval = git_parse_maybe_bool(v);
                if (0 <= boolval) {
                        fast_forward = boolval ? FF_ALLOW : FF_NO;
@@ -1294,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (!pull_twohead) {
                char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM");
                if (default_strategy && !strcmp(default_strategy, "ort"))
-                       pull_twohead = "ort";
+                       pull_twohead = xstrdup("ort");
        }
 
        init_diff_ui_defaults();
@@ -1793,6 +1795,8 @@ done:
        }
        strbuf_release(&buf);
        free(branch_to_free);
+       free(pull_twohead);
+       free(pull_octopus);
        discard_index(the_repository->index);
        return ret;
 }