format-patch: unleak "-v <num>"
commit5b8db44bdd619dc5ec4dcdac5cb3ca194ebdd046
authorJunio C Hamano <gitster@pobox.com>
Sun, 15 Jan 2023 08:03:39 +0000 (15 00:03 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Jan 2023 18:31:45 +0000 (16 10:31 -0800)
tree287f51fe477e9b64bd58961674f1894de9d63294
parentc48035d29b4e524aed3a32f0403676f0d9128863
format-patch: unleak "-v <num>"

The "subject_prefix" member of "struct revision" usually is set to a
borrowed string (either a string literal like "PATCH" that appear in
the program text as a hardcoded default, or the value of
"format.subjectprefix") and is never freed when the containing
revision structure is released.  The "-v <num>" codepath however
violates this rule and stores a pointer to an allocated string to
this member, relinquishing the responsibility to free it when it is
done using the revision structure, leading to a small one-time leak.

Instead, keep track of the string it allocates to let the revision
structure borrow, and clean it up when it is done.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c