From: Jonas Fonseca Date: Tue, 26 Apr 2005 22:00:01 +0000 (+0200) Subject: [PATCH] read_tree_recursive(): Fix leaks X-Git-Tag: v0.99~593 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1c9da46da4fe5cf99c5f6ab251419d0f412ecfba;p=git.git [PATCH] read_tree_recursive(): Fix leaks Fix two potential leaks. Signed-off-by: Jonas Fonseca Signed-off-by: Petr Baudis --- diff --git a/tree.c b/tree.c index a978c53a3..ca800a85f 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] = '/';