Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
[PATCH] read_tree_recursive(): Fix leaks
author
Jonas Fonseca
<fonseca@diku.dk>
Tue, 26 Apr 2005 22:00:01 +0000
(
00:00
+0200)
committer
Petr Baudis
<xpasky@machine.sinus.cz>
Wed, 11 May 2005 20:47:46 +0000
(22:47 +0200)
Fix two potential leaks.
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Signed-off-by: Petr Baudis <pasky@ucw.cz>
tree.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
62d046a
)
diff --git
a/tree.c
b/tree.c
index a978c53a308fa36fd4c666c3035bc17626fdc871..ca800a85f771be1bd10d6575d93ca05bd3fc381c 100644
(file)
--- 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);
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);
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;
return -1;
+ }
+ newbase = xmalloc(baselen + 1 + pathlen);
memcpy(newbase, base, baselen);
memcpy(newbase + baselen, path, pathlen);
newbase[baselen + pathlen] = '/';
memcpy(newbase, base, baselen);
memcpy(newbase + baselen, path, pathlen);
newbase[baselen + pathlen] = '/';