]> git.99rst.org Git - git.git/commit
history: streamline message preparation and plug file stream leak
authorJunio C Hamano <redacted>
Mon, 29 Jun 2026 16:08:42 +0000 (09:08 -0700)
committerJunio C Hamano <redacted>
Mon, 29 Jun 2026 16:19:36 +0000 (09:19 -0700)
commitebb4d2ffa34e8c37796cc1be14216af5b91869aa
tree8aa63c3c915f6f6b2f107036820b2e7ba5fee983
parentd205234cb05a5e330c0f7f5b3ea764533a74d69e
history: streamline message preparation and plug file stream leak

An early part of fill_commit_message() function uses write_file_buf()
to write out what was prepared in a strbuf, which is primarily meant
for use by callers that have their own message prepared fully and
called as the last thing to flush it to the destination file.

However, the function then opens a file stream in append mode to
further write into it.  It may have been understandable if this was
a later addition, but it seems it came from a single commit,
d205234c (builtin/history: implement "reword" subcommand,
2026-01-13), which is somewhat puzzling, but anyway...

Just open the file stream upfront for writing, write the message
the function has in the strbuf, and then keep writing whatever it
wants to write to the same open file stream.

And do not forget to close the stream.  We are about to pass the
resulting file to an external editor, and on some systems, notably
Windows, you are not supposed to keep a file open while expecting
another program to access it.

Diagnosed-by: Johannes Schindelin <redacted>
Signed-off-by: Junio C Hamano <redacted>
builtin/history.c
git clone https://git.99rst.org/PROJECT