Commit Diff


commit - a4e59b37021326e304c311825ba52a52b02bd9c0
commit + 2c97de1a26686adf2a6377bc4ef18d1aec6a1f3a
blob - 2459a29176c0bc8fa2026cc2faf0ee60a693c2b9
blob + 5b7494d98c40b53aa98c04053d6fbf4a83975802
--- src/libmach/elf.c
+++ src/libmach/elf.c
@@ -191,7 +191,7 @@ elfinit(int fd)
 		ElfHdrBytes h32;
 		ElfHdrBytes64 h64;
 	} hdrb;
-	void *p;
+	void *p = nil;
 	ElfSect *s;
 
 	e = mallocz(sizeof(Elf), 1);
@@ -234,6 +234,7 @@ elfinit(int fd)
 		unpackprog(h, &e->prog[i], p);
 	}
 	free(p);
+	p = nil;
 
 	e->nsect = h->shnum;
 	if(e->nsect == 0)
@@ -247,6 +248,7 @@ elfinit(int fd)
 		unpacksect(h, &e->sect[i], p);
 	}
 	free(p);
+	p = nil;
 
 	if(h->shstrndx >= e->nsect){
 		fprint(2, "warning: bad string section index %d >= %d", h->shstrndx, e->nsect);
@@ -287,6 +289,7 @@ nosects:
 	return e;
 
 err:
+	free(p);
 	free(e->sect);
 	free(e->prog);
 	free(e->shstrtab);