Skip to contentSkip to conversation

read_tree_recursive(): Fix leaks

PATCH New Jonas Fonseca 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 read_tree_recursive(): Fix leaks

Fix two potential leaks.

---
commit 74f5ad9d566408b4d352570ccde67ece0f2650a7 tree 7a6c485bceed70459c1855ab3c4d8ddfdeeb65d1 parent a738ed98e4557877f8bcd3b992aa55579b22b9d1 author Jonas Fonseca <[email protected]> 1114555146 +0200 committer Jonas Fonseca <[email protected]> 1114555146 +0200

 tree.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
tree.c (mode:100644 sha1:7c55bb9bfa1565dc9df5cab31207a02004d7fe10) renamed from tree.c (mode:100644 sha1:15a16d560619aee80e41bf816dd8474a3253b1a5) +5 -2
Index: tree.c
===================================================================
@@ -39,14 +39,17 @@
 		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] = '/';
Signature · 1 line
Jonas Fonseca