diff --git a/LibOS/shim/src/elf/shim_rtld.c b/LibOS/shim/src/elf/shim_rtld.c index dc4dd167..a6ce7dae 100644 --- a/LibOS/shim/src/elf/shim_rtld.c +++ b/LibOS/shim/src/elf/shim_rtld.c @@ -404,10 +404,15 @@ call_lose: if (type == OBJECT_LOAD && header->e_phoff + maplength <= (size_t) fbp_len) { ElfW(Phdr) * new_phdr = (ElfW(Phdr) *) malloc (maplength); + if (!new_phdr) { + errstring = "new_phdr malloc failure"; + goto call_lose; + } if ((ret = (*seek) (file, header->e_phoff, SEEK_SET)) < 0 || (ret = (*read) (file, new_phdr, maplength)) < 0) { errstring = "cannot read file data"; errval = ret; + free(new_phdr); goto call_lose; } phdr = new_phdr;