All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Lehmann <Jens.Lehmann@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] Fix memory leak in submodule.c
Date: Sun, 31 Jan 2010 17:43:49 +0100	[thread overview]
Message-ID: <4B65B345.1090907@web.de> (raw)

The strbuf used in add_submodule_odb() was never released. So for every
submodule - populated or not - we leaked its object directory name when
using "git diff*" with the --submodule option.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
 submodule.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/submodule.c b/submodule.c
index 6f7c210..7d70c4f 100644
--- a/submodule.c
+++ b/submodule.c
@@ -10,17 +10,19 @@ static int add_submodule_odb(const char *path)
 {
 	struct strbuf objects_directory = STRBUF_INIT;
 	struct alternate_object_database *alt_odb;
+	int ret = 0;

 	strbuf_addf(&objects_directory, "%s/.git/objects/", path);
-	if (!is_directory(objects_directory.buf))
-		return -1;
-
+	if (!is_directory(objects_directory.buf)) {
+		ret = -1;
+		goto done;
+	}
 	/* avoid adding it twice */
 	for (alt_odb = alt_odb_list; alt_odb; alt_odb = alt_odb->next)
 		if (alt_odb->name - alt_odb->base == objects_directory.len &&
 				!strncmp(alt_odb->base, objects_directory.buf,
 					objects_directory.len))
-			return 0;
+			goto done;

 	alt_odb = xmalloc(objects_directory.len + 42 + sizeof(*alt_odb));
 	alt_odb->next = alt_odb_list;
@@ -31,7 +33,9 @@ static int add_submodule_odb(const char *path)
 	alt_odb->name[41] = '\0';
 	alt_odb_list = alt_odb;
 	prepare_alt_odb();
-	return 0;
+done:
+	strbuf_release(&objects_directory);
+	return ret;
 }

 void show_submodule_summary(FILE *f, const char *path,
-- 
1.7.0.rc1.141.gd3fd.dirty

             reply	other threads:[~2010-01-31 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-31 16:43 Jens Lehmann [this message]
2010-01-31 19:23 ` [PATCH] Fix memory leak in submodule.c 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=4B65B345.1090907@web.de \
    --to=jens.lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.