[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>
This commit is contained in:
Jonas Fonseca 2005-04-27 00:00:01 +02:00 committed by Petr Baudis
parent 62d046a07b
commit 1c9da46da4

7
tree.c
View File

@ -39,14 +39,17 @@ static int read_tree_recursive(void *buffer, unsigned long size,
if (S_ISDIR(mode)) { if (S_ISDIR(mode)) {
int retval; int retval;
int pathlen = strlen(path); int pathlen = strlen(path);
char *newbase = xmalloc(baselen + 1 + pathlen); char *newbase;
void *eltbuf; void *eltbuf;
char elttype[20]; char elttype[20];
unsigned long eltsize; unsigned long eltsize;
eltbuf = read_sha1_file(sha1, elttype, &eltsize); eltbuf = read_sha1_file(sha1, elttype, &eltsize);
if (!eltbuf || strcmp(elttype, "tree")) if (!eltbuf || strcmp(elttype, "tree")) {
if (eltbuf) free(eltbuf);
return -1; return -1;
}
newbase = xmalloc(baselen + 1 + pathlen);
memcpy(newbase, base, baselen); memcpy(newbase, base, baselen);
memcpy(newbase + baselen, path, pathlen); memcpy(newbase + baselen, path, pathlen);
newbase[baselen + pathlen] = '/'; newbase[baselen + pathlen] = '/';