From: "Lidong Yan via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Lidong Yan <502024330056@smail.nju.edu.cn>,
Lidong Yan <502024330056@smail.nju.edu.cn>
Subject: [PATCH] sequencer: fix memory leak if `update_squash_messages()` failed
Date: Wed, 14 May 2025 12:44:00 +0000 [thread overview]
Message-ID: <pull.1964.git.git.1747226641249.gitgitgadget@gmail.com> (raw)
From: Lidong Yan <502024330056@smail.nju.edu.cn>
In sequencer.c:update_squash_messages, `repo_logmsg_reencode` returns
either an allocated reencode string or commit buffer if no encode is
needed. To free `repo_logmsg_reencode` result, `repo_unuse_commit_buffer`
should be used. However, when encountering the error("unknown command..."),
the absence of `repo_unuse_commit_buffer` results in a memory leak. I
think we should add a `repo_unuse_commit_buffer` before return.
Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
---
sequencer: fix memory leak if update_squash_messages() failed
In sequencer.c:update_squash_messages, repo_logmsg_reencode returns
either an allocated reencode string or commit buffer if no encode is
needed. To free repo_logmsg_reencode result, repo_unuse_commit_buffer
should be used. However, when encountering the error("unknown
command..."), the absence of repo_unuse_commit_buffer results in a
memory leak. I think we should add a repo_unuse_commit_buffer before
return.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1964%2Fbrandb97%2Ffix-sequencer-leak-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1964/brandb97/fix-sequencer-leak-v1
Pull-Request: https://github.com/git/git/pull/1964
sequencer.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sequencer.c b/sequencer.c
index b5c4043757e..f288a303eaa 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2138,8 +2138,10 @@ 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
+ } else {
+ repo_unuse_commit_buffer(r, commit, message);
return error(_("unknown command: %d"), command);
+ }
repo_unuse_commit_buffer(r, commit, message);
if (!res)
base-commit: 6f84262c44a89851c3ae5a6e4c1a9d06b2068d75
--
gitgitgadget
next reply other threads:[~2025-05-14 12:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-14 12:44 Lidong Yan via GitGitGadget [this message]
2025-05-15 10:08 ` [PATCH] sequencer: fix memory leak if `update_squash_messages()` failed Phillip Wood
2025-05-15 16:20 ` Junio C Hamano
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=pull.1964.git.git.1747226641249.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=502024330056@smail.nju.edu.cn \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.