git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonas Fonseca <fonseca@diku.dk>
To: Linus Torvalds <torvalds@osdl.org>, git@vger.kernel.org
Subject: [PATCH] Fix memory leaks in read_tree_recursive()
Date: Thu, 5 May 2005 01:39:36 +0200	[thread overview]
Message-ID: <20050504233936.GA25873@diku.dk> (raw)
In-Reply-To: <20050504231959.GA25475@diku.dk>

This patch fixes memory leaks in read_tree_recursive().

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

---

Sorry, typo in the previous patch. I will try to be more careful.
This patch has already been applied to cogito.

--- 571c0f4599fbeefd995bbc24480add1575c36c94/tree.c  (mode:100644 sha1:4a26603f6e32866c0db8a01ac1c228be801f76c6)
+++ uncommitted/tree.c  (mode:100644)
@@ -39,14 +39,18 @@
 		if (S_ISDIR(mode)) {
 			int retval;
 			int pathlen = strlen(path);
-			char *newbase = xmalloc(baselen + 1 + pathlen);
+			char *newbase;
 			void *eltbuf;
 			char elttype[20];
 			unsigned long eltsize;
 
 			eltbuf = read_sha1_file(sha1, elttype, &eltsize);
-			if (!eltbuf || strcmp(elttype, "tree"))
+			if (!eltbuf || strcmp(elttype, "tree")) {
+				if (eltbuf) free(eltbuf);
 				return -1;
+			}
+
+			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
 			memcpy(newbase + baselen, path, pathlen);
 			newbase[baselen + pathlen] = '/';

-- 
Jonas Fonseca

  reply	other threads:[~2005-05-04 23:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-04 23:19 [PATCH] Fix memory leaks in read_tree_recursive() Jonas Fonseca
2005-05-04 23:39 ` Jonas Fonseca [this message]
2005-05-04 23:43 ` Junio C Hamano
2005-05-05  0:08   ` Jonas Fonseca

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=20050504233936.GA25873@diku.dk \
    --to=fonseca@diku.dk \
    --cc=git@vger.kernel.org \
    --cc=torvalds@osdl.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).