Skip to content

Commit 7935a02

Browse files
pks-tgitster
authored andcommitted
builtin/log: fix leaking branch name when creating cover letters
When calling `make_cover_letter()` without a branch name, we try to derive the branch name by calling `find_branch_name()`. But while this function returns an allocated string, we never free the result and thus have a memory leak. Fix this. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 34968e5 commit 7935a02

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

builtin/log.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
14341434
int need_8bit_cte = 0;
14351435
struct pretty_print_context pp = {0};
14361436
struct commit *head = list[0];
1437+
char *to_free = NULL;
14371438

14381439
if (!cmit_fmt_is_mail(rev->commit_format))
14391440
die(_("cover letter needs email format"));
@@ -1455,7 +1456,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
14551456
}
14561457

14571458
if (!branch_name)
1458-
branch_name = find_branch_name(rev);
1459+
branch_name = to_free = find_branch_name(rev);
14591460

14601461
pp.fmt = CMIT_FMT_EMAIL;
14611462
pp.date_mode.type = DATE_RFC2822;
@@ -1466,6 +1467,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
14661467
encoding, need_8bit_cte, cfg);
14671468
fprintf(rev->diffopt.file, "%s\n", sb.buf);
14681469

1470+
free(to_free);
14691471
free(pp.after_subject);
14701472
strbuf_release(&sb);
14711473

t/t3206-range-diff.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='range-diff tests'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
# Note that because of the range-diff's heuristics, test_commit does more

0 commit comments

Comments
 (0)