Skip to content

Commit 71e01a0

Browse files
pks-tgitster
authored andcommitted
builtin/merge: always store allocated strings in pull_twohead
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc06676 commit 71e01a0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

builtin/merge.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,19 @@ static int git_merge_config(const char *k, const char *v,
611611
return 0;
612612
}
613613

614-
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
614+
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) {
615615
show_diffstat = git_config_bool(k, v);
616-
else if (!strcmp(k, "merge.verifysignatures"))
616+
} else if (!strcmp(k, "merge.verifysignatures")) {
617617
verify_signatures = git_config_bool(k, v);
618-
else if (!strcmp(k, "pull.twohead"))
618+
} else if (!strcmp(k, "pull.twohead")) {
619+
FREE_AND_NULL(pull_twohead);
619620
return git_config_string(&pull_twohead, k, v);
620-
else if (!strcmp(k, "pull.octopus"))
621+
} else if (!strcmp(k, "pull.octopus")) {
622+
FREE_AND_NULL(pull_octopus);
621623
return git_config_string(&pull_octopus, k, v);
622-
else if (!strcmp(k, "commit.cleanup"))
624+
} else if (!strcmp(k, "commit.cleanup")) {
623625
return git_config_string(&cleanup_arg, k, v);
624-
else if (!strcmp(k, "merge.ff")) {
626+
} else if (!strcmp(k, "merge.ff")) {
625627
int boolval = git_parse_maybe_bool(v);
626628
if (0 <= boolval) {
627629
fast_forward = boolval ? FF_ALLOW : FF_NO;
@@ -1294,7 +1296,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12941296
if (!pull_twohead) {
12951297
char *default_strategy = getenv("GIT_TEST_MERGE_ALGORITHM");
12961298
if (default_strategy && !strcmp(default_strategy, "ort"))
1297-
pull_twohead = "ort";
1299+
pull_twohead = xstrdup("ort");
12981300
}
12991301

13001302
init_diff_ui_defaults();
@@ -1793,6 +1795,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
17931795
}
17941796
strbuf_release(&buf);
17951797
free(branch_to_free);
1798+
free(pull_twohead);
1799+
free(pull_octopus);
17961800
discard_index(the_repository->index);
17971801
return ret;
17981802
}

0 commit comments

Comments
 (0)