- Fix deletion using an ad-hoc functor to avoid memory leaks, instead that ptr_fun(operator delete). Valgrind says we're doing well with History\!

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@787 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-20 21:50:28 +00:00
parent 69a7ee03eb
commit 19ee5c1884
8 changed files with 62 additions and 8 deletions

View File

@ -24,6 +24,8 @@
#include "sub_request.hh"
#include "thread.hh"
#include "deletor.tcc"
#include <algorithm>
#include <cassert>
#include <functional>
@ -162,7 +164,8 @@ ConcreteEnvironment::~ConcreteEnvironment()
{
// This call will invoke the DynamicProcess virtual destructor
// Which will delete on cascade all DynamicThreads and so on.
for_each(_processes.begin(), _processes.end(), ptr_fun(operator delete));
for_each(_processes.begin(), _processes.end(),
memory::deletor<Process>());
// We do the same with Resources.
for(Resources::iterator it = _resources.begin(); it != _resources.end(); it++)

View File

@ -35,6 +35,7 @@
#include "history_observer.hh"
#include "concrete_history.hh"
#include "deletor.tcc"
#include "smartp.tcc"
#include <algorithm>
@ -44,6 +45,7 @@
using namespace sgpem;
using namespace std;
using memory::smart_ptr;
using memory::deletor;
// ---------------
@ -88,7 +90,8 @@ ConcreteHistory::ConcreteHistory()
ConcreteHistory::~ConcreteHistory()
{
for_each(_snapshots.begin(), _snapshots.end(), ptr_fun(operator delete));
for_each(_snapshots.begin(), _snapshots.end(),
deletor<ConcreteEnvironment>());
}
ConcreteHistory::ConcreteHistory(const ConcreteHistory& h) :
@ -391,7 +394,7 @@ ConcreteHistory::reset(bool notify)
Snapshots::iterator it = _snapshots.begin();
it++; // Skip first environment that we saved
for_each(it, _snapshots.end(), ptr_fun(operator delete));
for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>());
_snapshots.resize(1); // Truncate to keep only our "model"
if(notify)

View File

@ -23,6 +23,8 @@
#include "dynamic_thread.hh"
#include "serialize_visitor.hh"
#include "deletor.tcc"
#include <algorithm>
#include <functional>
#include <cassert>
@ -49,7 +51,8 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) :
DynamicProcess::~DynamicProcess()
{
for_each(_dynamic_threads.begin(), _dynamic_threads.end(), ptr_fun(operator delete));
for_each(_dynamic_threads.begin(), _dynamic_threads.end(),
memory::deletor<DynamicThread>());
}
std::vector<Thread*>

View File

@ -24,6 +24,7 @@
#include "dynamic_thread.hh"
#include "serialize_visitor.hh"
#include "deletor.tcc"
#include "smartp.tcc"
#include <algorithm>
@ -69,7 +70,8 @@ DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner
DynamicRequest::~DynamicRequest()
{
for_each(_dynamic_subrequests.begin(), _dynamic_subrequests.end(), ptr_fun(operator delete));
for_each(_dynamic_subrequests.begin(), _dynamic_subrequests.end(),
memory::deletor<DynamicSubRequest>());
}

View File

@ -113,7 +113,7 @@ DynamicSubRequest::get_state() const
DynamicSubRequest::state
DynamicSubRequest::set_state(state new_state)
{
state temp;
state temp = _state;
_state = new_state;
return temp;
}

View File

@ -27,6 +27,7 @@
#include <functional>
#include <cassert>
#include "deletor.tcc"
#include "smartp.tcc"
using namespace sgpem;
@ -68,7 +69,8 @@ DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent)
DynamicThread::~DynamicThread()
{
for_each(_dynamic_requests.begin(), _dynamic_requests.end(), ptr_fun(operator delete));
for_each(_dynamic_requests.begin(), _dynamic_requests.end(),
memory::deletor<DynamicRequest>());
}

View File

@ -24,6 +24,7 @@
#include "module.hh"
#include "global_preferences.hh"
#include "deletor.tcc"
#include "singleton.tcc"
#include <glibmm/fileutils.h>
@ -48,7 +49,8 @@ PluginManager::rescan_dirs()
{
Module* module = NULL;
for_each(_modules.begin(), _modules.end(), ptr_fun(operator delete));
for_each(_modules.begin(), _modules.end(),
memory::deletor<Module>());
_modules.clear();
GlobalPreferences& prefs = GlobalPreferences::get_instance();

39
src/templates/deletor.tcc Normal file
View File

@ -0,0 +1,39 @@
// src/templates/deletor.tcc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef DELETOR_TCC
#define DELETOR_TCC 1
#include <functional>
namespace memory
{
template<typename T>
struct deletor : public std::unary_function<void, T*>
{
inline void operator()(T* o) { delete o; }
};
} //~ namespace memory
#endif