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

[PATCH 2/2] bugreport: slightly better memory management

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Sep 4, 2021, 02:12 UTC
Message-ID
<20210904021231.88534-3-carenas@gmail.com>
In-Reply-To
<20210904021231.88534-1-carenas@gmail.com>

238b439d69 (bugreport: add tool to generate debugging info, 2020-04-16) introduces an UNLEAK for a strbuf that contains the buffer that gets flushed to disk earlier, instead of simply cleaning the buffer.

do so, and while at it, move the free() call for another temporary string closer to its creator, so it is easier to keep track of.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 builtin/bugreport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 17042381c3..a9bedde1e8 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -152,6 +152,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
 	strbuf_addstr(&report_path, "git-bugreport-");
 	strbuf_addftime(&report_path, option_suffix, localtime_r(&now, &tm), 0, 0);
 	strbuf_addstr(&report_path, ".txt");
+	free(prefixed_filename);
 
 	switch (safe_create_leading_directories(report_path.buf)) {
 	case SCLD_OK:
@@ -181,6 +182,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
 		die_errno(_("unable to write to %s"), report_path.buf);
 
 	close(report);
+	strbuf_release(&buffer);
 
 	/*
 	 * We want to print the path relative to the user, but we still need the
@@ -191,8 +193,6 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
 	fprintf(stderr, _("Created new report at '%s'.\n"),
 		user_relative_path);
 
-	free(prefixed_filename);
-	UNLEAK(buffer);
 	UNLEAK(report_path);
 	return !!launch_editor(report_path.buf, NULL, NULL);
 }
-- 
2.33.0.481.g26d3bed244
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 8 in “Documentation: fix default directory of git bugreport -o”
  1. Documentation: fix default directory of git bugreport -oBagas Sanjaya, Sep 3, 2021
  2. bugreport papercutsCarlo Marcelo Arenas Belón, Sep 4, 2021
  3. 1/2 bugreport: avoid duplicating options in usage()Carlo Marcelo Arenas Belón, Sep 4, 2021
  4. Junio C HamanoSep 7, 2021
  5. 2/2 bugreport: slightly better memory managementCarlo Marcelo Arenas Belón, Sep 4, 2021
  6. Junio C HamanoSep 7, 2021
  7. Bagas SanjayaSep 4, 2021
  8. Junio C HamanoSep 7, 2021

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.