From: Jonas Fonseca <fonseca@diku.dk>
To: Linus Torvalds <torvalds@osdl.org>
Cc: git@vger.kernel.org
Subject: [PATCH] Fix memory leaks in read_tree_recursive()
Date: Thu, 5 May 2005 01:19:59 +0200 [thread overview]
Message-ID: <20050504231959.GA25475@diku.dk> (raw)
This patch fixes memory leaks in the error path of
read_tree_recursive().
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
--- 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) mem_free(eltbuf);
return -1;
+ }
+
+ newbase = xmalloc(baselen + 1 + pathlen);
memcpy(newbase, base, baselen);
memcpy(newbase + baselen, path, pathlen);
newbase[baselen + pathlen] = '/';
--
Jonas Fonseca
next reply other threads:[~2005-05-04 23:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-04 23:19 Jonas Fonseca [this message]
2005-05-04 23:39 ` [PATCH] Fix memory leaks in read_tree_recursive() Jonas Fonseca
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=20050504231959.GA25475@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 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.