From deffa58e4536c6753764d775ec2160c1c07fd0b6 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 6 Jan 2012 20:04:57 +0000 Subject: Fix another memory leak (better methods possibly available, but this will suffice for now) --- project2/cgi/cgiAppEngine.h | 1 - project2/cgi/cgiStagePresent.cpp | 3 +-- project2/common/commonObjects.cpp | 5 +++-- project2/common/commonObjects.h | 1 + project2/common/scriptLoader.cpp | 6 ++++++ project2/common/scriptLoader.h | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index a7648d1..64f081d 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -102,7 +102,6 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink virtual HttpHeaderPtr getHeader() const; protected: mutable MultiRowSetPresenterPtr presenter; - ScriptNodePtr root; }; /// The built-in fail-safe not found stage diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp index 2ca6147..152b906 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -9,8 +9,7 @@ CgiApplicationEngine::PresentStage::PresentStage(const CgiEnvironment * e, Scrip CgiApplicationEngine::ResponseStage(e, s->root()), CommonObjects(s->root()), CheckHost(s->root()), - ViewHost(s->root()), - root(s->root()) + ViewHost(s->root()) { s->loader.addLoadTarget(s->root(), Storer::into(&outputOptions)); s->loader.addLoadTarget(s->root(), Storer::into(&presenter)); diff --git a/project2/common/commonObjects.cpp b/project2/common/commonObjects.cpp index bc932b8..0e58cc8 100644 --- a/project2/common/commonObjects.cpp +++ b/project2/common/commonObjects.cpp @@ -16,6 +16,7 @@ CommonObjects::CommonObjects(ScriptNodePtr s) : CommonObjects::~CommonObjects() { + script->loader.discardLoadTargets(); } RowSetPtr @@ -36,9 +37,9 @@ CommonObjects::loadDataSource(const std::string & name) const void CommonObjects::loadScriptComponents() const { - if (script) { + if (!scriptLoaded) { script->load(this, true); - script.reset(); + scriptLoaded = true; } } diff --git a/project2/common/commonObjects.h b/project2/common/commonObjects.h index 5c4b574..b70185c 100644 --- a/project2/common/commonObjects.h +++ b/project2/common/commonObjects.h @@ -37,6 +37,7 @@ class CommonObjects : public virtual IntrusivePtrBase { RowSets rowSets; mutable DataSources datasources; mutable ScriptReaderPtr script; + mutable bool scriptLoaded; private: DataSources::const_iterator loadDataSource(const std::string & name) const; diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp index db256a9..6d5abdb 100644 --- a/project2/common/scriptLoader.cpp +++ b/project2/common/scriptLoader.cpp @@ -49,6 +49,12 @@ LoaderBase::addLoadTargetSub(ScriptNodePtr src, const Glib::ustring & name, bool } } +void +LoaderBase::discardLoadTargets() +{ + targets.clear(); +} + ScriptNodePtr LoaderBase::getSub(ScriptNodePtr root, const Glib::ustring & name, bool required) { diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h index b187ebb..b2faecd 100644 --- a/project2/common/scriptLoader.h +++ b/project2/common/scriptLoader.h @@ -31,6 +31,7 @@ class LoaderBase { void addLoadTarget(ScriptNodePtr src, boost::intrusive_ptr target); void addLoadTargetSub(ScriptNodePtr src, const Glib::ustring & name, bool required, boost::intrusive_ptr target); + void discardLoadTargets(); static void onAllComponents(const boost::function1 &); -- cgit v1.2.3