diff --git a/dfhack/DFProcess-linux-SHM.cpp b/dfhack/DFProcess-linux-SHM.cpp index ea53ef544..204b6ac1a 100644 --- a/dfhack/DFProcess-linux-SHM.cpp +++ b/dfhack/DFProcess-linux-SHM.cpp @@ -46,7 +46,7 @@ using namespace DFHack; class SHMProcess::Private { public: - Private() + Private(Process * self_) { memdescriptor = NULL; process_ID = 0; @@ -62,10 +62,12 @@ class SHMProcess::Private suspend_lock = -1; attachmentIdx = 0; locked = false; + self = self_; }; ~Private(){}; memory_info * memdescriptor; DFWindow * window; + Process * self; pid_t process_ID; char *shm_addr; int shm_ID; @@ -262,9 +264,10 @@ bool SHMProcess::Private::GetLocks() } SHMProcess::SHMProcess(uint32_t PID, vector< memory_info* >& known_versions) -: d(new Private()) +: d(new Private(this)) { d->process_ID = PID; + d->memdescriptor = 0; if(!attach()) { // couldn't attach to process @@ -335,9 +338,9 @@ bool SHMProcess::Private::validate(vector & known_versions) try{ if(hash == (*it)->getString("md5")) // are the md5 hashes the same? { - memory_info * m = *it; + memory_info *m = new memory_info(**it); memdescriptor = m; - m->setParentProcess((Process*)this); + m->setParentProcess(dynamic_cast( self )); identified = true; // cerr << "identified " << m->getVersion() << endl; return true; @@ -357,7 +360,8 @@ SHMProcess::~SHMProcess() { detach(); } - // destroy data model. this is assigned by processmanager + if(d->memdescriptor) + delete d->memdescriptor; if(d->window) { delete d->window; diff --git a/dfhack/DFProcess-linux-wine.cpp b/dfhack/DFProcess-linux-wine.cpp index 24ff9cc64..ceaa37299 100644 --- a/dfhack/DFProcess-linux-wine.cpp +++ b/dfhack/DFProcess-linux-wine.cpp @@ -34,7 +34,7 @@ using namespace DFHack; class WineProcess::Private { public: - Private() + Private(Process * self_) { my_descriptor = NULL; my_handle = NULL; @@ -43,10 +43,12 @@ class WineProcess::Private attached = false; suspended = false; memFileHandle = 0; + self = self_; }; ~Private(){}; DFWindow* my_window; memory_info * my_descriptor; + Process * self; ProcessHandle my_handle; uint32_t my_pid; string memFile; @@ -58,7 +60,7 @@ class WineProcess::Private }; WineProcess::WineProcess(uint32_t pid, vector & known_versions) -: d(new Private()) +: d(new Private(this)) { char dir_name [256]; char exe_link_name [256]; @@ -69,6 +71,7 @@ WineProcess::WineProcess(uint32_t pid, vector & known_versions) int target_result; d->identified = false; + d->my_descriptor = 0; sprintf(dir_name,"/proc/%d/", pid); sprintf(exe_link_name,"/proc/%d/exe", pid); @@ -147,9 +150,11 @@ bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file // are the md5 hashes the same? if(memory_info::OS_WINDOWS == (*it)->getOS() && hash == thishash) { - memory_info * m = *it; + + // keep track of created memory_info object so we can destroy it later + memory_info *m = new memory_info(**it); my_descriptor = m; - m->setParentProcess((Process*)this); + m->setParentProcess(dynamic_cast( self )); my_handle = my_pid = pid; // tell WineProcess about the /proc/PID/mem file memFile = mem_file; @@ -166,6 +171,9 @@ WineProcess::~WineProcess() { detach(); } + // destroy our copy of the memory descriptor + if(d->my_descriptor) + delete d->my_descriptor; if(d->my_window) delete d->my_window; delete d; diff --git a/dfhack/DFProcess-linux.cpp b/dfhack/DFProcess-linux.cpp index 1a04d3f7a..5ae965e11 100644 --- a/dfhack/DFProcess-linux.cpp +++ b/dfhack/DFProcess-linux.cpp @@ -33,7 +33,7 @@ using namespace DFHack; class NormalProcess::Private { public: - Private() + Private(Process * self_) { my_descriptor = NULL; my_handle = NULL; @@ -42,6 +42,7 @@ class NormalProcess::Private attached = false; suspended = false; memFileHandle = 0; + self = self_; }; ~Private(){}; DFWindow* my_window; @@ -53,11 +54,12 @@ class NormalProcess::Private bool attached; bool suspended; bool identified; + Process * self; bool validate(char * exe_file, uint32_t pid, char * mem_file, vector & known_versions); }; NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_versions) -: d(new Private()) +: d(new Private(this)) { char dir_name [256]; char exe_link_name [256]; @@ -68,6 +70,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_version int target_result; d->identified = false; + d->my_descriptor = 0; sprintf(dir_name,"/proc/%d/", pid); sprintf(exe_link_name,"/proc/%d/exe", pid); @@ -125,8 +128,9 @@ bool NormalProcess::Private::validate(char * exe_file,uint32_t pid, char * memFi memory_info * m = *it; if (memory_info::OS_LINUX == m->getOS()) { - my_descriptor = m; - m->setParentProcess((Process*)this); + memory_info *m2 = new memory_info(*m); + my_descriptor = m2; + m2->setParentProcess(dynamic_cast( self )); my_handle = my_pid = pid; } else @@ -154,6 +158,9 @@ NormalProcess::~NormalProcess() { detach(); } + // destroy our copy of the memory descriptor + if(d->my_descriptor) + delete d->my_descriptor; // destroy data model. this is assigned by processmanager if(d->my_window) delete d->my_window; diff --git a/dfhack/modules/Buildings.cpp b/dfhack/modules/Buildings.cpp index 65c0d6b06..b9f44e139 100644 --- a/dfhack/modules/Buildings.cpp +++ b/dfhack/modules/Buildings.cpp @@ -110,7 +110,7 @@ bool Buildings::Read (const uint32_t index, t_building & building) // transform int32_t type = -1; - d->d->offset_descriptor->resolveObjectToClassID (temp, type); + d->owner->getDescriptor()->resolveObjectToClassID (temp, type); building.origin = temp; building.vtable = bld_40d.vtable; building.x1 = bld_40d.x1; diff --git a/dfhack/modules/Maps.cpp b/dfhack/modules/Maps.cpp index 8785892ad..b562ed655 100644 --- a/dfhack/modules/Maps.cpp +++ b/dfhack/modules/Maps.cpp @@ -142,7 +142,6 @@ bool Maps::Start() d->block = new uint32_t[mx*my*mz]; uint32_t *temp_x = new uint32_t[mx]; uint32_t *temp_y = new uint32_t[my]; - uint32_t *temp_z = new uint32_t[mz]; p->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x); for (uint32_t x = 0; x < mx; x++) @@ -158,7 +157,6 @@ bool Maps::Start() } delete [] temp_x; delete [] temp_y; - delete [] temp_z; return true; } diff --git a/dfhack/modules/Materials.cpp b/dfhack/modules/Materials.cpp index 527e6f6d9..93ca96e93 100644 --- a/dfhack/modules/Materials.cpp +++ b/dfhack/modules/Materials.cpp @@ -44,10 +44,14 @@ class Materials::Private Materials::Materials(APIPrivate * d_) { + d = new Private; d->d = d_; d->owner = d_->p; } -Materials::~Materials(){} +Materials::~Materials() +{ + delete d; +} /* { LABEL_53: diff --git a/output/Memory.xml b/output/Memory.xml index c3b2fa892..4350fac70 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1060,6 +1060,7 @@ size=212 0x159c 0x179c 0x1D9C + 0x0D9c