Fix memleak with Context not cleaning up.

develop
Petr Mrázek 2010-08-14 01:25:18 +02:00
parent 7fbdd6c69a
commit a159707250
10 changed files with 25 additions and 15 deletions

@ -84,6 +84,10 @@ dfprospector
============
Lists all available minerals on the map and how much of them there is.
dfprobe
============
Can be used to determine tile properties.
dfreveal
========
Reveals the whole map, waits for input and hides it again. If you close

@ -59,6 +59,7 @@ Context::Context (Process* p) : d (new DFContextShared())
Context::~Context()
{
cerr << "called Context destructor" << endl;
Detach();
delete d;
}
@ -88,6 +89,7 @@ bool Context::Detach()
{
if (!d->p->detach())
{
cerr << "Context::Detach failed!" << endl;
return false;
}
d->shm_start = 0;

@ -569,10 +569,7 @@ bool SHMProcess::attach()
bool SHMProcess::detach()
{
if(!d->attached)
{
return false;
}
if(!d->attached) return true;
if(d->locked)
{
resume();

@ -331,7 +331,7 @@ bool WineProcess::attach()
bool WineProcess::detach()
{
if(!d->attached) return false;
if(!d->attached) return true;
if(!d->suspended) suspend();
int result = 0;
// close /proc/PID/mem

@ -318,7 +318,7 @@ bool NormalProcess::attach()
bool NormalProcess::detach()
{
if(!d->attached) return false;
if(!d->attached) return true;
if(!d->suspended) suspend();
int result = 0;
// close /proc/PID/mem

@ -632,10 +632,7 @@ bool SHMProcess::attach()
bool SHMProcess::detach()
{
if(!d->attached)
{
return false;
}
if(!d->attached) return true;
//cerr << "detach" << endl;// FIXME: throw
if(d->locked)
{

@ -249,10 +249,7 @@ bool NormalProcess::attach()
bool NormalProcess::detach()
{
if(!d->attached)
{
return false;
}
if(!d->attached) return true;
resume();
d->attached = false;
return true;

@ -33,7 +33,7 @@ namespace DFHack
class DFHACK_EXPORT Module
{
public:
~Module(){};
virtual ~Module(){};
virtual bool Start(){return true;};// default start...
virtual bool Finish() = 0;// everything should have a Finish()
// should Context call Finish when Resume is called?

@ -123,8 +123,10 @@ Maps::Maps(DFContextShared* _d)
Maps::~Maps()
{
cerr << "called Maps destructor" << endl;
if(d->Started)
Finish();
delete d;
}
/*-----------------------------------*

@ -102,6 +102,17 @@ int main (void)
Cman.Refresh(&inval);
int nCont = Cman.size();
int nInval = inval.size();
DFHack::Context * cont = Cman.getSingleContext();
if(cont)
{
if(cont->Attach())
cont->getMaps();
bool result = cont->Detach();
if(!result)
{
cerr << "Something went horribly wrong during detach" << endl;
}
}
cout << "Contexts:" << endl;
for(int i = 0; i < nCont; i++)