git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: Lidong Yan via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org,  Lidong Yan <502024330056@smail.nju.edu.cn>
Subject: Re: [PATCH] sequencer: fix memory leak if `update_squash_messages()` failed
Date: Thu, 15 May 2025 09:20:00 -0700	[thread overview]
Message-ID: <xmqqldqx3ky7.fsf@gitster.g> (raw)
In-Reply-To: <935822b9-33e5-457e-95a7-64058777b52a@gmail.com> (Phillip Wood's message of "Thu, 15 May 2025 11:08:36 +0100")

Phillip Wood <phillip.wood123@gmail.com> writes:

> Looking at the code, if we reaching that call to error() is a
> programming error as we should only call update_squash_messages() if
> command is TODO_FIXUP or TODO_SQUASH so I think we'd be better to
> replace error(...) with BUG(...) which calls abort() which means we
> don't care if there is a leak or not.

It is a valid way to "fix" a leak, certainly ;-).

I am curious if Lidong's tool would notice an unreachable code if
only the first hunk of the attached patch is applied.  The "else"
clause in the second hunk would become unreachable.


diff --git c/sequencer.c w/sequencer.c
index b5c4043757..269637d427 100644
--- c/sequencer.c
+++ w/sequencer.c
@@ -2071,6 +2071,9 @@ static int update_squash_messages(struct repository *r,
 	const char *message, *body;
 	const char *encoding = get_commit_output_encoding();
 
+	if (!(command == TODO_FIXUP || command == TODO_SQUASH))
+		BUG("update_squash_messages with command %d", command);
+
 	if (ctx->current_fixup_count > 0) {
 		struct strbuf header = STRBUF_INIT;
 		char *eol;
@@ -2138,8 +2141,6 @@ static int update_squash_messages(struct repository *r,
 		strbuf_addstr(&buf, "\n\n");
 		strbuf_add_commented_lines(&buf, body, strlen(body),
 					   comment_line_str);
-	} else
-		return error(_("unknown command: %d"), command);
 	repo_unuse_commit_buffer(r, commit, message);
 
 	if (!res)

  reply	other threads:[~2025-05-15 16:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 12:44 [PATCH] sequencer: fix memory leak if `update_squash_messages()` failed Lidong Yan via GitGitGadget
2025-05-15 10:08 ` Phillip Wood
2025-05-15 16:20   ` Junio C Hamano [this message]
2025-05-15 16:43     ` lidongyan
2025-05-25 10:19 ` [PATCH v2] sequencer: replace error() with BUG() in update_squash_messages() Lidong Yan via GitGitGadget
2025-05-28 22:16   ` Junio C Hamano
2025-05-29 13:39     ` Phillip Wood
2025-05-30  4:29       ` Junio C Hamano
2025-06-02 13:59         ` Phillip Wood
2025-05-30  1:52   ` [PATCH v3 0/2] " Lidong Yan via GitGitGadget
2025-05-30  1:52     ` [PATCH v3 1/2] " Lidong Yan via GitGitGadget
2025-05-30 13:35       ` Junio C Hamano
2025-05-30  1:52     ` [PATCH v3 2/2] BUG(): remove leading underscore of the format string Lidong Yan via GitGitGadget
2025-05-30 13:15       ` Junio C Hamano
2025-06-03  2:01     ` [PATCH v4 0/2] sequencer: replace error() with BUG() in update_squash_messages() Lidong Yan via GitGitGadget
2025-06-03  2:01       ` [PATCH v4 1/2] " Lidong Yan via GitGitGadget
2025-06-03  2:01       ` [PATCH v4 2/2] BUG(): remove leading underscore of the format string Lidong Yan via GitGitGadget
2025-06-03 17:40         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqldqx3ky7.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=502024330056@smail.nju.edu.cn \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).