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. Lists all available minerals on the map and how much of them there is.
dfprobe
============
Can be used to determine tile properties.
dfreveal dfreveal
======== ========
Reveals the whole map, waits for input and hides it again. If you close 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() Context::~Context()
{ {
cerr << "called Context destructor" << endl;
Detach(); Detach();
delete d; delete d;
} }
@ -88,6 +89,7 @@ bool Context::Detach()
{ {
if (!d->p->detach()) if (!d->p->detach())
{ {
cerr << "Context::Detach failed!" << endl;
return false; return false;
} }
d->shm_start = 0; d->shm_start = 0;

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

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

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

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

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

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

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

@ -102,6 +102,17 @@ int main (void)
Cman.Refresh(&inval); Cman.Refresh(&inval);
int nCont = Cman.size(); int nCont = Cman.size();
int nInval = inval.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; cout << "Contexts:" << endl;
for(int i = 0; i < nCont; i++) for(int i = 0; i < nCont; i++)