git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonas Fonseca <fonseca@diku.dk>
To: pasky@ucw.cz
Cc: git@vger.kernel.org
Subject: [PATCH] read_tree_recursive(): Fix leaks
Date: Wed, 27 Apr 2005 01:00:01 +0200	[thread overview]
Message-ID: <20050426230001.GB28560@diku.dk> (raw)

Fix two potential leaks.

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

---
commit 74f5ad9d566408b4d352570ccde67ece0f2650a7
tree 7a6c485bceed70459c1855ab3c4d8ddfdeeb65d1
parent a738ed98e4557877f8bcd3b992aa55579b22b9d1
author Jonas Fonseca <fonseca@diku.dk> 1114555146 +0200
committer Jonas Fonseca <fonseca@diku.dk> 1114555146 +0200

 tree.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

Index: tree.c
===================================================================
--- 2447d3a399200c8f736344822969f88f675612dd/tree.c  (mode:100644 sha1:15a16d560619aee80e41bf816dd8474a3253b1a5)
+++ 7a6c485bceed70459c1855ab3c4d8ddfdeeb65d1/tree.c  (mode:100644 sha1:7c55bb9bfa1565dc9df5cab31207a02004d7fe10)
@@ -39,14 +39,17 @@
 		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-04-26 22:55 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

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

  git send-email \
    --in-reply-to=20050426230001.GB28560@diku.dk \
    --to=fonseca@diku.dk \
    --cc=git@vger.kernel.org \
    --cc=pasky@ucw.cz \
    /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).