Skip to content

Commit 49af1b7

Browse files
pks-tgitster
authored andcommitted
builtin/pull: fix leaking "ff" option
The `opt_ff` field gets populated either via `OPT_PASSTHRU` via `config_get_ff()` or when `--rebase` is passed. So we sometimes end up overriding the value in `opt_ff` with another value, but we do not free the old value, causing a memory leak. Adapt the type of the variable to be `char *` and consistently assign allocated strings to it such that we can easily free it when it is being overridden. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04ff800 commit 49af1b7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

builtin/pull.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static const char *opt_squash;
8484
static const char *opt_commit;
8585
static const char *opt_edit;
8686
static const char *cleanup_arg;
87-
static const char *opt_ff;
87+
static char *opt_ff;
8888
static const char *opt_verify_signatures;
8989
static const char *opt_verify;
9090
static int opt_autostash = -1;
@@ -1024,8 +1024,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10241024
* "--rebase" can override a config setting of
10251025
* pull.ff=only.
10261026
*/
1027-
if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only"))
1028-
opt_ff = "--ff";
1027+
if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only")) {
1028+
free(opt_ff);
1029+
opt_ff = xstrdup("--ff");
1030+
}
10291031
}
10301032

10311033
if (opt_rebase < 0)
@@ -1135,7 +1137,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
11351137

11361138
if (can_ff) {
11371139
/* we can fast-forward this without invoking rebase */
1138-
opt_ff = "--ff-only";
1140+
free(opt_ff);
1141+
opt_ff = xstrdup("--ff-only");
11391142
ret = run_merge();
11401143
} else {
11411144
ret = run_rebase(&newbase, &upstream);

t/t7601-merge-pull-config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='git merge
44
55
Testing pull.* configuration parsing and other things.'
66

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

910
test_expect_success 'setup' '

0 commit comments

Comments
 (0)