From 4a142f35f521ef554fee9b18dde8880d382d0f58 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 25 Feb 2001 14:02:57 +0000 Subject: [PATCH] Renamed MemBuffer::free() to dealloc() in order to better support malloc debugging libraries like mpatrol. committer: mfx 983109777 +0000 --- src/conf.h | 10 +++++----- src/mem.cpp | 6 +++--- src/mem.h | 6 +++++- src/p_vmlinz.cpp | 4 ++-- src/p_w32pe.cpp | 8 ++++---- src/p_wcle.cpp | 10 +++++----- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/conf.h b/src/conf.h index 9bb1d62b..01684ddf 100644 --- a/src/conf.h +++ b/src/conf.h @@ -348,31 +348,31 @@ typedef RETSIGTYPE (SIGTYPEENTRY *sig_type)(int); #define UPX_MIN3(a,b,c) ((a) <= (b) ? UPX_MIN(a,c) : UPX_MIN(b,c)) -#if 0 && defined(__cplusplus) +#if 0 && defined(__cplusplus) && !defined(new) && !defined(delete) // global operators - debug inline void *operator new(size_t l) { void *p = malloc(l); - printf("new %6ld %p\n",(long)l,p); + printf("new %6ld %p\n",(long)l,p); fflush(stdout); return p; } inline void *operator new[](size_t l) { void *p = malloc(l); - printf("new %6ld %p\n",(long)l,p); + printf("new[] %6ld %p\n",(long)l,p); fflush(stdout); return p; } inline void operator delete(void *p) { - printf("delete %p\n",p); + printf("delete %p\n",p); fflush(stdout); if (p) free(p); } inline void operator delete[](void *p) { - printf("delete %p\n",p); + printf("delete[] %p\n",p); fflush(stdout); if (p) free(p); } diff --git a/src/mem.cpp b/src/mem.cpp index 2d9bb0ba..1d8a1b21 100644 --- a/src/mem.cpp +++ b/src/mem.cpp @@ -44,10 +44,10 @@ MemBuffer::MemBuffer(unsigned size) : MemBuffer::~MemBuffer() { - this->free(); + this->dealloc(); } -void MemBuffer::free() +void MemBuffer::dealloc() { if (alloc_ptr) ::free(alloc_ptr); @@ -69,7 +69,7 @@ unsigned MemBuffer::getSize() const void MemBuffer::alloc(unsigned size, unsigned base_offset) { #if 0 - this->free(); + this->dealloc(); #else // don't automaticlly free a used buffer #endif diff --git a/src/mem.h b/src/mem.h index 4fb4b437..ff0a8441 100644 --- a/src/mem.h +++ b/src/mem.h @@ -44,7 +44,7 @@ public: void allocForCompression(unsigned uncompressed_size); void allocForUncompression(unsigned uncompressed_size); - void free(); + void dealloc(); const unsigned char *getBuf() const { return ptr; } unsigned getSize() const; @@ -66,10 +66,14 @@ private: MemBuffer& operator= (MemBuffer const &); // { return *this; } // disable dynamic allocation +#ifndef new static void *operator new (size_t); // {} static void *operator new[] (size_t); // {} +#endif +#ifndef delete //static void operator delete (void *) {} //static void operator delete[] (void *) {} +#endif }; #endif /* already included */ diff --git a/src/p_vmlinz.cpp b/src/p_vmlinz.cpp index 6698da5c..6190bae9 100644 --- a/src/p_vmlinz.cpp +++ b/src/p_vmlinz.cpp @@ -186,7 +186,7 @@ int PackVmlinuzI386::decompressKernel() break; // realloc and try again unsigned s = ibuf.getSize(); - ibuf.free(); + ibuf.dealloc(); ibuf.alloc(3 * s / 2); } if (fd >= 0) @@ -232,7 +232,7 @@ void PackVmlinuzI386::readKernel() memcpy(setup_buf, obuf, setup_size); //OutputFile::dump("setup.img", setup_buf, setup_size); - obuf.free(); + obuf.dealloc(); obuf.allocForCompression(klen); ph.u_len = klen; diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 474884bb..63c78039 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -2155,7 +2155,7 @@ void PackW32Pe::rebuildRelocs(upx_byte *& extrainfo) else memcpy (obuf + ODADDR(PEDIR_RELOC) - rvamin,oxrelocs,soxrelocs); delete [] oxrelocs; oxrelocs = NULL; - wrkmem.free(); + wrkmem.dealloc(); ODSIZE(PEDIR_RELOC) = soxrelocs; } @@ -2236,7 +2236,7 @@ void PackW32Pe::unpack(OutputFile *fo) extrainfo += sizeof(pe_section_t) * objs; // read the noncompressed section - ibuf.free(); + ibuf.dealloc(); ibuf.alloc(isection[2].size); fi->seek(isection[2].rawdataptr,SEEK_SET); fi->readx(ibuf,isection[2].size); @@ -2284,7 +2284,7 @@ void PackW32Pe::unpack(OutputFile *fo) // write decompressed file if (fo) { - ibuf.free(); + ibuf.dealloc(); ibuf.alloc(osection[0].rawdataptr); memset(ibuf,0,osection[0].rawdataptr); infoHeader("[Writing uncompressed file]"); @@ -2298,7 +2298,7 @@ void PackW32Pe::unpack(OutputFile *fo) fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign)); copyOverlay(fo, overlay, &obuf); } - ibuf.free(); + ibuf.dealloc(); } /* diff --git a/src/p_wcle.cpp b/src/p_wcle.cpp index 33fae77d..ab1954f7 100644 --- a/src/p_wcle.cpp +++ b/src/p_wcle.cpp @@ -432,7 +432,7 @@ void PackWcle::encodeImage(const Filter *ft) ph.overlap_overhead = findOverlapOverhead(oimage+RESERVED, 512); buildLoader(ft); - ibuf.free(); + ibuf.dealloc(); soimage = (ph.c_len + 3) &~ 3; } @@ -477,7 +477,7 @@ void PackWcle::pack(OutputFile *fo) ifixups[sofixups++] = (unsigned char) ih.automatic_data_object; unsigned ic = objects*sizeof(*iobject_table); memcpy(ifixups+sofixups,iobject_desc,ic); - iobject_desc.free(); + iobject_desc.dealloc(); sofixups += ic; set_le32(ifixups+sofixups,ih.init_esp_offset+IOT(ih.init_ss_object-1,my_base_address)); // old stack pointer @@ -566,7 +566,7 @@ void PackWcle::decodeFixups() { upx_byte *p = oimage + soimage; - iimage.free(); + iimage.dealloc(); MemBuffer tmpbuf; unsigned fixupn = unoptimizeReloc32(&p,oimage,&tmpbuf,1); @@ -584,7 +584,7 @@ void PackWcle::decodeFixups() set_le32(oimage+jc,r); } set_le32(wrkmem+ic*8,0xFFFFFFFF); // end of 32-bit offset fixups - tmpbuf.free(); + tmpbuf.dealloc(); // selector fixups and self-relative fixups const upx_byte *selector_fixups = p; @@ -788,7 +788,7 @@ void PackWcle::unpack(OutputFile *fo) handleStub(fo); readObjectTable(); - iobject_desc.free(); + iobject_desc.dealloc(); readPageMap(); readResidentNames(); readEntryTable();