Skip to content

Commit e490bea

Browse files
committed
Merge branch 'jk/format-patch-message-id-unleak'
Leakfix. * jk/format-patch-message-id-unleak: format-patch: free elements of rev.ref_message_ids list format-patch: free rev.message_id when exiting
2 parents cbc882e + c6d26a9 commit e490bea

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

builtin/log.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
14061406
}
14071407
}
14081408

1409-
static const char *clean_message_id(const char *msg_id)
1409+
static char *clean_message_id(const char *msg_id)
14101410
{
14111411
char ch;
14121412
const char *a, *z, *m;
@@ -1424,7 +1424,7 @@ static const char *clean_message_id(const char *msg_id)
14241424
if (!z)
14251425
die(_("insane in-reply-to: %s"), msg_id);
14261426
if (++z == m)
1427-
return a;
1427+
return xstrdup(a);
14281428
return xmemdupz(a, z - a);
14291429
}
14301430

@@ -2310,11 +2310,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
23102310

23112311
if (in_reply_to || thread || cover_letter) {
23122312
rev.ref_message_ids = xmalloc(sizeof(*rev.ref_message_ids));
2313-
string_list_init_nodup(rev.ref_message_ids);
2313+
string_list_init_dup(rev.ref_message_ids);
23142314
}
23152315
if (in_reply_to) {
2316-
const char *msgid = clean_message_id(in_reply_to);
2317-
string_list_append(rev.ref_message_ids, msgid);
2316+
char *msgid = clean_message_id(in_reply_to);
2317+
string_list_append_nodup(rev.ref_message_ids, msgid);
23182318
}
23192319
rev.numbered_files = just_numbers;
23202320
rev.patch_suffix = fmt_patch_suffix;
@@ -2370,8 +2370,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
23702370
&& (!cover_letter || rev.nr > 1))
23712371
free(rev.message_id);
23722372
else
2373-
string_list_append(rev.ref_message_ids,
2374-
rev.message_id);
2373+
string_list_append_nodup(rev.ref_message_ids,
2374+
rev.message_id);
23752375
}
23762376
gen_message_id(&rev, oid_to_hex(&commit->object.oid));
23772377
}
@@ -2420,6 +2420,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
24202420
strbuf_release(&rdiff_title);
24212421
strbuf_release(&sprefix);
24222422
free(to_free);
2423+
free(rev.message_id);
24232424
if (rev.ref_message_ids)
24242425
string_list_clear(rev.ref_message_ids, 0);
24252426
free(rev.ref_message_ids);

t/t9001-send-email.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test_description='git send-email'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7-
# no longer TEST_PASSES_SANITIZE_LEAK=true - format-patch --thread leaks
7+
TEST_PASSES_SANITIZE_LEAK=true
88
. ./test-lib.sh
99

1010
# May be altered later in the test

0 commit comments

Comments
 (0)