git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] am: fix commit buffer leak in get_commit_info()

From
Jeff King <peff@peff.net>
Date
Apr 27, 2017, 03:25 UTC
Message-ID
<20170427032555.imjr5to4uys2cz4k@sigill.intra.peff.net>
In-Reply-To
<20170427032503.rgz3bnctnxdn3hin@sigill.intra.peff.net>

Calling logmsg_reencode() may allocate a buffer for the commit message (because we need to load it from disk, or because it needs re-encoded). We must "unuse" it afterwards to free it.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/am.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/builtin/am.c b/builtin/am.c
index 805f56cec..baab951ed 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1421,6 +1421,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
 		die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
 	state->msg = xstrdup(msg + 2);
 	state->msg_len = strlen(state->msg);
+	unuse_commit_buffer(commit, buffer);
 }
 
 /**
-- 
2.13.0.rc0.465.ga1e654229
Previous: Jeff KingNext: Jeff King
Message 2 of 5 in “fix memory leak in git-am”
  1. 0/3 fix memory leak in git-amJeff King, Apr 27, 2017
  2. 1/3 am: fix commit buffer leak in get_commit_info()Jeff King, Apr 27, 2017
  3. 2/3 am: simplify allocations in get_commit_info()Jeff King, Apr 27, 2017
  4. 3/3 am: shorten ident_split variable name in get_commit_info()Jeff King, Apr 27, 2017
  5. Junio C HamanoApr 27, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.