public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix memory leak in function handle_content_type
@ 2025-06-13 16:52 Alex via GitGitGadget
  2025-06-13 16:59 ` Kristoffer Haugsbakk
  0 siblings, 1 reply; 8+ messages in thread
From: Alex via GitGitGadget @ 2025-06-13 16:52 UTC (permalink / raw)
  To: git; +Cc: Alex, jinyaoguo

From: jinyaoguo <guo846@purdue.edu>

The function handle_content_type allocates memory for boundary
using xmalloc(sizeof(struct strbuf)). If (++mi->content_top >=
&mi->content[MAX_BOUNDARIES]) is true, the function returns
without freeing boundary.

Signed-off-by: Alex Guo <alexguo1023@gmail.com>
---
    Fix memory leak in function handle_content_type
    
    The function handle_content_type allocates memory for boundary using
    xmalloc(sizeof(struct strbuf)). If (++mi->content_top >=
    &mi->content[MAX_BOUNDARIES]) is true, the function returns without
    freeing boundary.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1997%2Fmugitya03%2Fmlk-2-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1997/mugitya03/mlk-2-v1
Pull-Request: https://github.com/git/git/pull/1997

 mailinfo.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mailinfo.c b/mailinfo.c
index ee4597da6be..e0ea358311f 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -266,6 +266,9 @@ static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
 			error("Too many boundaries to handle");
 			mi->input_error = -1;
 			mi->content_top = &mi->content[MAX_BOUNDARIES] - 1;
+			strbuf_release(boundary);
+			free(boundary);
+			boundary = NULL;
 			return;
 		}
 		*(mi->content_top) = boundary;

base-commit: 9edff09aec9b5aaa3d5528129bb279a4d34cf5b3
-- 
gitgitgadget

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

end of thread, other threads:[~2025-06-16  1:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13 16:52 [PATCH] Fix memory leak in function handle_content_type Alex via GitGitGadget
2025-06-13 16:59 ` Kristoffer Haugsbakk
2025-06-13 18:36   ` Jinyao Guo
2025-06-13 19:06     ` Junio C Hamano
2025-06-13 19:26       ` Jinyao Guo
2025-06-14 16:45         ` Junio C Hamano
2025-06-15 12:55         ` Lidong Yan
2025-06-16  1:01           ` Junio C Hamano

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