Fixes for crash bugs and memory corruption.

develop
Petr Mrázek 2010-02-25 17:37:40 +01:00
parent 230af4310f
commit de5b2ecb4e
5 changed files with 32 additions and 28 deletions

@ -1022,6 +1022,8 @@ bool API::ReadSettlement(const int32_t &index, t_settlement & settlement)
{ {
if(!d->settlementsInited) if(!d->settlementsInited)
return false; return false;
if(!d->p_settlements->getSize())
return false;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_settlements->at (index); uint32_t temp = * (uint32_t *) d->p_settlements->at (index);
settlement.origin = temp; settlement.origin = temp;
@ -1034,11 +1036,13 @@ bool API::ReadCurrentSettlement(t_settlement & settlement)
{ {
if(!d->settlementsInited) if(!d->settlementsInited)
return false; return false;
if(!d->p_current_settlement->getSize())
return false;
uint32_t temp = * (uint32_t *) d->p_current_settlement->at(0); uint32_t temp = * (uint32_t *) d->p_current_settlement->at(0);
settlement.origin = temp; settlement.origin = temp;
g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name); g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.world_x); g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int32_t), (uint8_t *) &settlement.local_x1); g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true; return true;
} }

@ -94,7 +94,12 @@ memory_info::memory_info(const memory_info &old)
d->hexvals = old.d->hexvals; d->hexvals = old.d->hexvals;
d->strings = old.d->strings; d->strings = old.d->strings;
d->base = old.d->base; d->base = old.d->base;
d->classes = old.d->classes; //d->classes = old.d->classes;
for(int i = 0; i < old.d->classes.size(); i++)
{
t_class * copy = new t_class(*old.d->classes[i]);
d->classes.push_back(copy);
}
d->classindex = old.d->classindex; d->classindex = old.d->classindex;
d->professions = old.d->professions; d->professions = old.d->professions;
d->jobs = old.d->jobs; d->jobs = old.d->jobs;
@ -107,7 +112,7 @@ memory_info::memory_info(const memory_info &old)
memory_info::~memory_info() memory_info::~memory_info()
{ {
// delete the vtables // delete the vtables
for(int i = 0; i < d->classes.size();i++) for(uint32_t i = 0; i < d->classes.size();i++)
{ {
delete d->classes[i]; delete d->classes[i];
} }

@ -72,6 +72,7 @@ namespace DFHack
{ {
delete subs[i]; delete subs[i];
} }
subs.clear();
} }
string classname; string classname;
uint32_t vtable; uint32_t vtable;

@ -476,10 +476,6 @@ bool SHMProcess::detach()
{ {
return false; return false;
} }
if(d->suspended)
{
resume();
}
// detach segment // detach segment
UnmapViewOfFile(d->my_shm); UnmapViewOfFile(d->my_shm);
// release it for some other client // release it for some other client

@ -68,9 +68,7 @@ bool ProcessEnumerator::findProcessess()
// Get the list of process identifiers. // Get the list of process identifiers.
DWORD ProcArray[2048], memoryNeeded, numProccesses; DWORD ProcArray[2048], memoryNeeded, numProccesses;
{ {
Process *p = new SHMProcess(d->meminfo->meminfo); Process * p = new SHMProcess(d->meminfo->meminfo);
delete p;
p = new SHMProcess(d->meminfo->meminfo);
if(p->isIdentified()) if(p->isIdentified())
{ {
d->processes.push_back(p); d->processes.push_back(p);