aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/log.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-03-19 20:35:33 -0400
committerJunio C Hamano <gitster@pobox.com>2024-03-19 17:54:16 -0700
commit305a68143cc0e9b714d71417efa9f0162dd07221 (patch)
tree0ccc59a20ce1c784df5d6f2c3c1be90b5784c7c8 /builtin/log.c
parentlog: do not set up extra_headers for non-email formats (diff)
downloadgit-305a68143cc0e9b714d71417efa9f0162dd07221.tar.gz
git-305a68143cc0e9b714d71417efa9f0162dd07221.zip
format-patch: return an allocated string from log_write_email_headers()
When pretty-printing a commit in the email format, we have to fill in the "after subject" field of the pretty_print_context with any extra headers the user provided (e.g., from "--to" or "--cc" options) plus any special MIME headers. We return an out-pointer that sometimes points to a newly heap-allocated string and sometimes not. To avoid leaking, we store the allocated version in a buffer with static lifetime, which is ugly. Worse, as we extend the header feature, we'll end up having to repeat this ugly pattern. Instead, let's have our out-pointer pass ownership back to the caller, and duplicate the string when necessary. This does mean one extra allocation per commit when you use extra headers, but in the context of format-patch which is showing diffs, I don't think that's even measurable. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/log.c')
-rw-r--r--builtin/log.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/builtin/log.c b/builtin/log.c
index de1c1cbec1..ebd3f642da 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1370,6 +1370,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
encoding, need_8bit_cte);
fprintf(rev->diffopt.file, "%s\n", sb.buf);
+ free(pp.after_subject);
strbuf_release(&sb);
shortlog_init(&log);