git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: bagasdotme@gmail.com, emilyshaffer@google.com,
	"Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: [PATCH 2/2] bugreport: slightly better memory management
Date: Fri,  3 Sep 2021 19:12:31 -0700	[thread overview]
Message-ID: <20210904021231.88534-3-carenas@gmail.com> (raw)
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


  parent reply	other threads:[~2021-09-04  2:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 11:59 [PATCH] Documentation: fix default directory of git bugreport -o Bagas Sanjaya
2021-09-04  2:12 ` bugreport papercuts Carlo Marcelo Arenas Belón
2021-09-04  2:12   ` [PATCH 1/2] bugreport: avoid duplicating options in usage() Carlo Marcelo Arenas Belón
2021-09-07 21:39     ` Junio C Hamano
2021-09-04  2:12   ` Carlo Marcelo Arenas Belón [this message]
2021-09-07 21:56     ` [PATCH 2/2] bugreport: slightly better memory management Junio C Hamano
2021-09-04  6:01   ` bugreport papercuts Bagas Sanjaya
2021-09-07 21:09 ` [PATCH] Documentation: fix default directory of git bugreport -o 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=20210904021231.88534-3-carenas@gmail.com \
    --to=carenas@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=emilyshaffer@google.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).