use killer-stash to resolve the AdviceSystem memory leak

This commit is contained in:
Fischlurch 2010-06-12 03:33:40 +02:00
parent cb838ba5b6
commit a93d8a42e4
2 changed files with 20 additions and 6 deletions

View file

@ -92,17 +92,21 @@
#include "lib/advice.hpp"
#include "lib/advice/index.hpp"
#include "lib/del-stash.hpp"
#include "lib/singleton.hpp"
#include "lib/util.hpp"
#include "include/logging.h"
#include <boost/noncopyable.hpp>
using lib::Singleton;
using util::unConst;
typedef void (DeleterFunc)(void*);
namespace lib {
namespace advice {
namespace { // ======= implementation of the AdviceSystem ============
class AdviceSystem
@ -110,6 +114,8 @@ namespace advice {
, boost::noncopyable
{
DelStash adviceDataRegistry_;
public:
AdviceSystem()
{
@ -121,12 +127,18 @@ namespace advice {
INFO (library, "Shutting down Advice system.");
}
void
manageAdviceData (PointOfAdvice* entry, DeleterFunc* how_to_delete)
{
adviceDataRegistry_.manage (entry, how_to_delete);
}
void discardEntry (const PointOfAdvice* storedProvision)
void
discardEntry (PointOfAdvice* storedProvision)
{
if (storedProvision)
{
UNIMPLEMENTED ("use stored management information to trigger deletion");
adviceDataRegistry_.kill (storedProvision);
}
}
};
@ -182,7 +194,7 @@ namespace advice {
void
AdviceLink::manageAdviceData (PointOfAdvice* entry, DeleterFunc* how_to_delete)
{
UNIMPLEMENTED ("store memory management information");
aSys().manageAdviceData (entry,how_to_delete);
}
@ -215,7 +227,7 @@ namespace advice {
if (previousProvision && !newProvision)
aSys().removeProvision (*previousProvision);
aSys().discardEntry (previousProvision);
aSys().discardEntry (unConst(previousProvision));
}
@ -235,7 +247,7 @@ namespace advice {
if (existingProvision)
aSys().removeProvision (*existingProvision);
aSys().discardEntry (existingProvision);
aSys().discardEntry (unConst(existingProvision));
}

View file

@ -224,12 +224,14 @@ namespace lib {
bool
isRegistered (const void* objAddress)
{
REQUIRE (objAddress);
return killers_.end() != findEntry (objAddress);
}
Killers::iterator
findEntry (const void* obj)
{
REQUIRE (obj);
return std::find(killers_.begin(),killers_.end(), obj);
}