[LibOS] Fix a memory leak in __map_elf_object() about variable pointer new_phdr

new_phdr is allocated using malloc, if failed, it may cause unpredictable behavior on read operation,
also causing resource leakage of new_phdr if read operation failed.

Signed-off-by: Gary <gang1.wang@intel.com>
This commit is contained in:
Gary
2019-02-15 18:59:44 +01:00
committed by Michał Kowalczyk
parent 7a5eb9246d
commit ddd4e3d20d
+5
View File
@@ -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;