Skip to content

Commit 1ca57be

Browse files
pks-tgitster
authored andcommitted
builtin/rebase: fix leaking commit.gpgsign value
In `get_replay_opts()`, we override the `gpg_sign` field that already got populated by `sequencer_init_config()` in case the user has "commit.gpgsign" set in their config. This creates a memory leak because we overwrite the previously assigned value, which may have already pointed to an allocated string. Let's plug the memory leak by freeing the value before we overwrite it. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 648abbe commit 1ca57be

File tree

5 files changed

+5
-0
lines changed

5 files changed

+5
-0
lines changed

builtin/rebase.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
186186
replay.committer_date_is_author_date =
187187
opts->committer_date_is_author_date;
188188
replay.ignore_date = opts->ignore_date;
189+
free(replay.gpg_sign);
189190
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
190191
replay.reflog_action = xstrdup(opts->reflog_action);
191192
if (opts->strategy)

sequencer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ static int git_sequencer_config(const char *k, const char *v,
303303
}
304304

305305
if (!strcmp(k, "commit.gpgsign")) {
306+
free(opts->gpg_sign);
306307
opts->gpg_sign = git_config_bool(k, v) ? xstrdup("") : NULL;
307308
return 0;
308309
}

t/t3404-rebase-interactive.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Initial setup:
2626
touch file "conflict".
2727
'
2828

29+
TEST_PASSES_SANITIZE_LEAK=true
2930
. ./test-lib.sh
3031

3132
. "$TEST_DIRECTORY"/lib-rebase.sh

t/t3435-rebase-gpg-sign.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_description='test rebase --[no-]gpg-sign'
88
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010

11+
TEST_PASSES_SANITIZE_LEAK=true
1112
. ./test-lib.sh
1213
. "$TEST_DIRECTORY/lib-rebase.sh"
1314
. "$TEST_DIRECTORY/lib-gpg.sh"

t/t7030-verify-tag.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='signed tag tests'
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
. "$TEST_DIRECTORY/lib-gpg.sh"
910

0 commit comments

Comments
 (0)