git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix memory leaks in read_tree_recursive()
@ 2005-05-04 23:19 Jonas Fonseca
  2005-05-04 23:39 ` Jonas Fonseca
  2005-05-04 23:43 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Jonas Fonseca @ 2005-05-04 23:19 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

This patch fixes memory leaks in the error path of
read_tree_recursive().

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

--- 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) mem_free(eltbuf);
 				return -1;
+			}
+
+			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
 			memcpy(newbase + baselen, path, pathlen);
 			newbase[baselen + pathlen] = '/';

-- 
Jonas Fonseca

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-05  0:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-04 23:19 [PATCH] Fix memory leaks in read_tree_recursive() Jonas Fonseca
2005-05-04 23:39 ` Jonas Fonseca
2005-05-04 23:43 ` Junio C Hamano
2005-05-05  0:08   ` Jonas Fonseca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).