public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH] repo_logmsg_reencode: fix memory leak when use repo_logmsg_reencode()
@ 2025-06-04  3:10 Lidong Yan via GitGitGadget
  2025-06-04  7:56 ` Patrick Steinhardt
  2025-06-05  6:27 ` [PATCH v2] " Lidong Yan via GitGitGadget
  0 siblings, 2 replies; 7+ messages in thread
From: Lidong Yan via GitGitGadget @ 2025-06-04  3:10 UTC (permalink / raw)
  To: git; +Cc: Lidong Yan, Lidong Yan

From: Lidong Yan <502024330056@smail•nju.edu.cn>

pretty.c:repo_logmsg_reencode() allocated memory should be freed with
repo_unuse_commit_buffer(). Callers sometimes forgot free it at exit
point. Add `repo_unuse_commit_buffer()` in insert_records_from_trailers
at builtin/shortlog.c and create_commit at builtin/replay.c

Signed-off-by: Lidong Yan <502024330056@smail•nju.edu.cn>
---
    repo_logmsg_reencode: fix memory leak when use repo_logmsg_reencode()
    
    pretty.c:repo_logmsg_reencode() allocated memory should be freed with
    repo_unuse_commit_buffer(). Callers sometimes forgot free it at exit
    point. Add repo_unuse_commit_buffer() in insert_records_from_trailers at
    builtin/shortlog.c and create_commit at builtin/replay.c.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1988%2Fbrandb97%2Ffix-reencode-leak-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1988/brandb97/fix-reencode-leak-v1
Pull-Request: https://github.com/git/git/pull/1988

 builtin/replay.c   | 1 +
 builtin/shortlog.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/builtin/replay.c b/builtin/replay.c
index 225cef08807..6172c8aacc9 100644
--- a/builtin/replay.c
+++ b/builtin/replay.c
@@ -84,6 +84,7 @@ static struct commit *create_commit(struct repository *repo,
 	obj = parse_object(repo, &ret);
 
 out:
+	repo_unuse_commit_buffer(the_repository, based_on, message);
 	free_commit_extra_headers(extra);
 	free_commit_list(parents);
 	strbuf_release(&msg);
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 30075b67be8..dfc7e85ae96 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -186,8 +186,10 @@ static void insert_records_from_trailers(struct shortlog *log,
 	commit_buffer = repo_logmsg_reencode(the_repository, commit, NULL,
 					     ctx->output_encoding);
 	body = strstr(commit_buffer, "\n\n");
-	if (!body)
+	if (!body) {
+		repo_unuse_commit_buffer(the_repository, commit, commit_buffer);
 		return;
+	}
 
 	trailer_iterator_init(&iter, body);
 	while (trailer_iterator_advance(&iter)) {

base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-06-06 12:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04  3:10 [PATCH] repo_logmsg_reencode: fix memory leak when use repo_logmsg_reencode() Lidong Yan via GitGitGadget
2025-06-04  7:56 ` Patrick Steinhardt
2025-06-04 10:50   ` lidongyan
2025-06-05  7:23   ` Jeff King
2025-06-06 12:22     ` lidongyan
2025-06-05  6:27 ` [PATCH v2] " Lidong Yan via GitGitGadget
2025-06-05  7:53   ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox