git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Matheus Tavares <matheus.bernardino@usp.br>
Subject: [PATCH] dir-iterator: release strbuf after use
Date: Wed, 7 Aug 2019 13:15:14 +0200	[thread overview]
Message-ID: <3729e2f1-2995-86ae-cfa0-a6fc4ca64917@web.de> (raw)

Signed-off-by: René Scharfe <l.s.r@web.de>
---
Patch generated with --function-context for easier review.

The plugged leak was added after v2.22.0 (2019-06-07) by 3012397e03
(dir-iterator: refactor state machine model, 2019-07-10).

 refs/files-backend.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index b1f8f53a09..d60767ab73 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2143,24 +2143,26 @@ static struct ref_iterator_vtable files_reflog_iterator_vtable = {
 static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
 						  const char *gitdir)
 {
 	struct dir_iterator *diter;
 	struct files_reflog_iterator *iter;
 	struct ref_iterator *ref_iterator;
 	struct strbuf sb = STRBUF_INIT;

 	strbuf_addf(&sb, "%s/logs", gitdir);

 	diter = dir_iterator_begin(sb.buf, 0);
-	if(!diter)
+	if (!diter) {
+		strbuf_release(&sb);
 		return empty_ref_iterator_begin();
+	}

 	iter = xcalloc(1, sizeof(*iter));
 	ref_iterator = &iter->base;

 	base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 0);
 	iter->dir_iterator = diter;
 	iter->ref_store = ref_store;
 	strbuf_release(&sb);

 	return ref_iterator;
 }
--
2.22.0

                 reply	other threads:[~2019-08-07 11:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3729e2f1-2995-86ae-cfa0-a6fc4ca64917@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=matheus.bernardino@usp.br \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).