From: Jonas Fonseca Date: Wed, 04 May 2005 23:39:36 GMT Subject: [PATCH] Fix memory leaks in read_tree_recursive() Message-ID: <20050504233936.GA25873@diku.dk> In-Reply-To: <20050504231959.GA25475@diku.dk> This patch fixes memory leaks in read_tree_recursive(). Signed-off-by: Jonas Fonseca --- 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