aboutsummaryrefslogtreecommitdiff
path: root/src/libmach/elf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libmach/elf.c')
-rw-r--r--src/libmach/elf.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libmach/elf.c b/src/libmach/elf.c
index 2459a291..b3cb9e8c 100644
--- a/src/libmach/elf.c
+++ b/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);
@@ -340,7 +343,7 @@ unpackhdr(ElfHdr *h, void *v)
h->e2 = e2;
h->e4 = e4;
h->e8 = e8;
-
+
if(h->class == ElfClass64)
goto b64;
@@ -385,7 +388,7 @@ unpackprog(ElfHdr *h, ElfProg *p, void *v)
if(h->class == ElfClass32) {
ElfProgBytes *b;
-
+
b = v;
e4 = h->e4;
p->type = e4(b->type);
@@ -398,7 +401,7 @@ unpackprog(ElfHdr *h, ElfProg *p, void *v)
p->align = e4(b->align);
} else {
ElfProgBytes64 *b;
-
+
b = v;
e4 = h->e4;
e8 = h->e8;
@@ -421,7 +424,7 @@ unpacksect(ElfHdr *h, ElfSect *s, void *v)
if(h->class == ElfClass32) {
ElfSectBytes *b;
-
+
b = v;
e4 = h->e4;
s->name = (char*)(uintptr)e4(b->name);
@@ -436,7 +439,7 @@ unpacksect(ElfHdr *h, ElfSect *s, void *v)
s->entsize = e4(b->entsize);
} else {
ElfSectBytes64 *b;
-
+
b = v;
e4 = h->e4;
e8 = h->e8;
@@ -551,4 +554,3 @@ elfsym(Elf *elf, int i, ElfSym *sym)
werrstr("symbol index out of range");
return -1;
}
-