summaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorJonas Fonseca <fonseca@diku.dk>2005-04-27 00:00:01 +0200
committerPetr Baudis <xpasky@machine.sinus.cz>2005-05-11 22:47:46 +0200
commit1c9da46da4fe5cf99c5f6ab251419d0f412ecfba (patch)
treeca9f4b973997ad861877aee778d44f25d14941a9 /tree.c
parent62d046a07b4cd4328d3d40aab097a1d97c4d7b20 (diff)
downloadgit-1c9da46da4fe5cf99c5f6ab251419d0f412ecfba.tar.gz
[PATCH] read_tree_recursive(): Fix leaks
Fix two potential leaks. Signed-off-by: Jonas Fonseca <fonseca@diku.dk> Signed-off-by: Petr Baudis <pasky@ucw.cz>
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/tree.c b/tree.c
index a978c53a30..ca800a85f7 100644
--- a/tree.c
+++ b/tree.c
@@ -39,14 +39,17 @@ static int read_tree_recursive(void *buffer, unsigned long size,
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] = '/';