Fix memory leak

modified:   p_lx_elf.cpp
This commit is contained in:
John Reiser 2016-09-20 20:43:48 -07:00
parent ad6914b938
commit d2830db94d

View File

@ -230,16 +230,14 @@ PackLinuxElf32::PackLinuxElf32help1(InputFile *f)
if (f && Elf32_Ehdr::ET_DYN!=e_type) {
unsigned const len = sz_phdrs + e_phoff;
assert(file_image == NULL);
file_image = New(char, len);
assert(file_image != NULL); // set by PackLinuxElf64help1
f->seek(0, SEEK_SET);
f->readx(file_image, len);
phdri= (Elf32_Phdr *)(e_phoff + file_image); // do not free() !!
}
if (f && Elf32_Ehdr::ET_DYN==e_type) {
// The DT_STRTAB has no designated length. Read the whole file.
assert(file_image == NULL);
file_image = New(char, file_size);
assert(file_image != NULL); // set by PackLinuxElf64help1
f->seek(0, SEEK_SET);
f->readx(file_image, file_size);
phdri= (Elf32_Phdr *)(e_phoff + file_image); // do not free() !!
@ -602,16 +600,14 @@ PackLinuxElf64::PackLinuxElf64help1(InputFile *f)
if (f && Elf64_Ehdr::ET_DYN!=e_type) {
unsigned const len = sz_phdrs + e_phoff;
assert(file_image == NULL);
file_image = New(char, len);
assert(file_image != NULL); // set by PackLinuxElf64help1
f->seek(0, SEEK_SET);
f->readx(file_image, len);
phdri= (Elf64_Phdr *)(e_phoff + file_image); // do not free() !!
}
if (f && Elf64_Ehdr::ET_DYN==e_type) {
// The DT_STRTAB has no designated length. Read the whole file.
assert(file_image == NULL);
file_image = New(char, file_size);
assert(file_image != NULL); // set by PackLinuxElf64help1
f->seek(0, SEEK_SET);
f->readx(file_image, file_size);
phdri= (Elf64_Phdr *)(e_phoff + file_image); // do not free() !!
@ -1666,8 +1662,7 @@ PackLinuxElf64ppcle::canPack()
if (Elf32_Ehdr::ET_DYN==get_te16(&ehdr->e_type)) {
// The DT_STRTAB has no designated length. Read the whole file.
assert(file_image == NULL);
file_image = New(char, file_size);
assert(file_image != NULL); // set by PackLinuxElf64help1
fi->seek(0, SEEK_SET);
fi->readx(file_image, file_size);
memcpy(&ehdri, ehdr, sizeof(Elf64_Ehdr));
@ -1842,8 +1837,7 @@ PackLinuxElf64amd::canPack()
if (Elf32_Ehdr::ET_DYN==get_te16(&ehdr->e_type)) {
// The DT_STRTAB has no designated length. Read the whole file.
assert(file_image == NULL);
file_image = New(char, file_size);
assert(file_image != NULL); // set by PackLinuxElf64help1
fi->seek(0, SEEK_SET);
fi->readx(file_image, file_size);
memcpy(&ehdri, ehdr, sizeof(Elf64_Ehdr));