1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Fix some small memory leaks. Minor cleanup.

This commit is contained in:
Markus F.X.J. Oberhumer 2010-04-10 13:57:25 +02:00
parent 9e3e80261b
commit a15ce00934
4 changed files with 67 additions and 10 deletions

View File

@ -113,6 +113,7 @@ struct PackerNames
{
PackerNames *self = (PackerNames *) user;
self->add(p);
delete p; p = NULL;
return NULL;
}
static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) {

View File

@ -1351,27 +1351,40 @@ void upx_sanity_check(void)
assert(TestBELE<BE32>::test());
assert(TestBELE<BE64>::test());
{
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
0, 0, 0, 0,
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
static const unsigned char dd[32]
#if 1 && (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__)
__attribute__((__aligned__(16)))
#endif
= { 0, 0, 0, 0, 0, 0, 0,
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
0, 0, 0, 0,
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
0, 0, 0, 0, 0 };
const unsigned char *d;
const N_BELE_RTP::AbstractPolicy *bele;
d = dd + 7;
assert(upx_adler32(d, 4) == 0x09f003f7);
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
bele = &N_BELE_RTP::be_policy;
assert(get_be16(d) == 0xfffe);
assert(bele->get16(d) == 0xfffe);
assert(get_be16_signed(d) == -2);
assert(get_be24(d) == 0xfffefd);
assert(bele->get24(d) == 0xfffefd);
assert(get_be24_signed(d) == -259);
assert(get_be32(d) == 0xfffefdfc);
assert(bele->get32(d) == 0xfffefdfc);
assert(get_be32_signed(d) == -66052);
bele = &N_BELE_RTP::le_policy;
assert(get_le16(d) == 0xfeff);
assert(bele->get16(d) == 0xfeff);
assert(get_le16_signed(d) == -257);
assert(get_le24(d) == 0xfdfeff);
assert(bele->get24(d) == 0xfdfeff);
assert(get_le24_signed(d) == -131329);
assert(get_le32(d) == 0xfcfdfeff);
assert(bele->get32(d) == 0xfcfdfeff);
assert(get_le32_signed(d) == -50462977);
assert(get_le64_signed(d) == ACC_INT64_C(-506097522914230529));
assert(find_be16(d, 2, 0xfffe) == 0);

View File

@ -167,7 +167,7 @@ PackLinuxElf::PackLinuxElf(InputFile *f)
PackLinuxElf::~PackLinuxElf()
{
delete[] file_image;
delete[] file_image; file_image = NULL;
}
void PackLinuxElf::pack3(OutputFile *fo, Filter &ft)
@ -400,6 +400,7 @@ PackLinuxElf32::PackLinuxElf32(InputFile *f)
shstrtab(NULL), n_elf_shnum(0),
sec_strndx(NULL), sec_dynsym(NULL), sec_dynstr(NULL)
{
memset(&ehdri, 0, sizeof(ehdri));
if (f) {
f->seek(0, SEEK_SET);
f->readx(&ehdri, sizeof(ehdri));
@ -408,7 +409,7 @@ PackLinuxElf32::PackLinuxElf32(InputFile *f)
PackLinuxElf32::~PackLinuxElf32()
{
delete[] phdri;
delete[] phdri; phdri = NULL;
}
PackLinuxElf64::PackLinuxElf64(InputFile *f)
@ -417,6 +418,7 @@ PackLinuxElf64::PackLinuxElf64(InputFile *f)
shstrtab(NULL), n_elf_shnum(0),
sec_strndx(NULL), sec_dynsym(NULL), sec_dynstr(NULL)
{
memset(&ehdri, 0, sizeof(ehdri));
if (f) {
f->seek(0, SEEK_SET);
f->readx(&ehdri, sizeof(ehdri));
@ -425,7 +427,7 @@ PackLinuxElf64::PackLinuxElf64(InputFile *f)
PackLinuxElf64::~PackLinuxElf64()
{
delete[] phdri;
delete[] phdri; phdri = NULL;
}
Linker* PackLinuxElf64amd::newLinker() const
@ -2033,9 +2035,6 @@ void PackLinuxElf64::pack2(OutputFile *fo, Filter &ft)
throwEOFException();
}
#include "bele.h"
using namespace N_BELE_CTP;
// Filter 0x50, 0x51 assume HostPolicy::isLE
static const int *
ARM_getFilters(bool const isBE)

View File

@ -162,54 +162,72 @@ Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
{
if ((p = func(new PackDjgpp2(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackTmt(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackWcle(f), user)) != NULL)
return p;
delete p; p = NULL;
#if 0
if ((p = func(new PackVxd(f), user)) != NULL)
return p;
delete p; p = NULL;
#endif
#if 0
if ((p = func(new PackW16Ne(f), user)) != NULL)
return p;
delete p; p = NULL;
#endif
if ((p = func(new PackW32Pe(f), user)) != NULL)
return p;
delete p; p = NULL;
}
if ((p = func(new PackArmPe(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackExe(f), user)) != NULL)
return p;
delete p; p = NULL;
//
// atari
//
if ((p = func(new PackTos(f), user)) != NULL)
return p;
delete p; p = NULL;
//
// linux kernel
//
if ((p = func(new PackVmlinuxARMEL(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackVmlinuxARMEB(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackVmlinuxPPC32(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackVmlinuxAMD64(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackVmlinuxI386(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackVmlinuzI386(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackBvmlinuzI386(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackVmlinuzARMEL(f), user)) != NULL)
return p;
delete p; p = NULL;
#if 0
if ((p = func(new PackElks8086(f), user)) != NULL)
return p;
delete p; p = NULL;
#endif
//
@ -222,75 +240,101 @@ Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
{
if ((p = func(new PackLinuxI386sep(f), user)) != NULL)
return p;
delete p; p = NULL;
}
#endif
if (o->o_unix.use_ptinterp) {
if ((p = func(new PackLinuxElf32x86interp(f), user)) != NULL)
return p;
delete p; p = NULL;
}
if ((p = func(new PackFreeBSDElf32x86(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackNetBSDElf32x86(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackOpenBSDElf32x86(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxElf32x86(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxElf64amd(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxElf32armLe(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxElf32armBe(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxElf32ppc(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxElf32mipsel(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxElf32mipseb(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxI386sh(f), user)) != NULL)
return p;
delete p; p = NULL;
}
if ((p = func(new PackBSDI386(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackMachFat(f), user)) != NULL) // cafebabe conflict
return p;
delete p; p = NULL;
if ((p = func(new PackLinuxI386(f), user)) != NULL) // cafebabe conflict
return p;
delete p; p = NULL;
//
// psone
//
if ((p = func(new PackPs1(f), user)) != NULL)
return p;
delete p; p = NULL;
//
// .sys and .com
//
if ((p = func(new PackSys(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackCom(f), user)) != NULL)
return p;
delete p; p = NULL;
// Mach (MacOS X PowerPC)
if ((p = func(new PackMachPPC32(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackMachI386(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackMachAMD64(f), user)) != NULL)
return p;
delete p; p = NULL;
if ((p = func(new PackMachARMEL(f), user)) != NULL)
return p;
delete p; p = NULL;
// 2010-03-12 omit these because PackMachBase<T>::pack4dylib (p_mach.cpp)
// does not understand what the Darwin (Apple Mac OS X) dynamic loader
// assumes about .dylib file structure.
//if ((p = func(new PackDylibI386(f), user)) != NULL)
// return p;
//delete p; p = NULL;
//if ((p = func(new PackDylibPPC32(f), user)) != NULL)
// return p;
//delete p; p = NULL;
//if ((p = func(new PackDylibAMD64(f), user)) != NULL)
// return p;
//delete p; p = NULL;
return NULL;
}