diff options
author | randomdan <randomdan@localhost> | 2012-01-04 18:21:01 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-01-04 18:21:01 +0000 |
commit | b98bd8df54eed1b10bf9d603f6aaec4cb5c8fc17 (patch) | |
tree | d5127d1886d8eeb1978eaa9d43a515ad03e7d1a9 | |
parent | Allowing specification of output encoding (diff) | |
download | project2-b98bd8df54eed1b10bf9d603f6aaec4cb5c8fc17.tar.bz2 project2-b98bd8df54eed1b10bf9d603f6aaec4cb5c8fc17.tar.xz project2-b98bd8df54eed1b10bf9d603f6aaec4cb5c8fc17.zip |
Address memory leaks that have snook in over time
-rw-r--r-- | project2/cgi/testCgi.cpp | 4 | ||||
-rw-r--r-- | project2/common/commonObjects.cpp | 4 | ||||
-rw-r--r-- | project2/common/scriptLoader.cpp | 5 | ||||
-rw-r--r-- | project2/common/scriptLoader.h | 1 | ||||
-rw-r--r-- | project2/common/scripts.cpp | 5 | ||||
-rw-r--r-- | project2/common/scripts.h | 7 | ||||
-rw-r--r-- | project2/uuid/uuid.cpp | 13 | ||||
-rw-r--r-- | project2/uuid/uuid.h | 1 | ||||
-rw-r--r-- | project2/xml/xmlScriptParser.cpp | 10 | ||||
-rw-r--r-- | project2/xml/xmlScriptParser.h | 5 |
10 files changed, 38 insertions, 17 deletions
diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp index 855e59b..624f2d7 100644 --- a/project2/cgi/testCgi.cpp +++ b/project2/cgi/testCgi.cpp @@ -7,7 +7,7 @@ #include "../files/optionsSource.h" #define TESTOPT(name, def, desc) \ - (name, Options::value(optStore.insert(OptStore::value_type(name, new std::string())).first->second, def), desc) + (name, Options::value(optStore.insert(OptStore::value_type(name, StrPtr(new std::string()))).first->second.get(), def), desc) class TestInput : public cgicc::CgiInput { public: class TestConfigConsumer : public ConfigConsumer { @@ -24,7 +24,7 @@ class TestInput : public cgicc::CgiInput { const Options * o; }; - typedef std::string * StrPtr; + typedef boost::shared_ptr<std::string> StrPtr; typedef std::map<std::string, StrPtr> OptStore; OptStore optStore; TestInput() : diff --git a/project2/common/commonObjects.cpp b/project2/common/commonObjects.cpp index b615b62..bc932b8 100644 --- a/project2/common/commonObjects.cpp +++ b/project2/common/commonObjects.cpp @@ -29,7 +29,7 @@ CommonObjects::loadDataSource(const std::string & name) const { ScriptReaderPtr dbs = Environment::getCurrent()->resolveScript(Environment::getCurrent()->datasourceRoot, name, true); dbs->loader.addLoadTarget(dbs->root(), Storer::into<ElementLoader>(&datasources)); - dbs->loader.collectAll(NULL, false, dbs->root()); + dbs->load(NULL, false); return safeMapFind<DataSourceNotFound>(datasources, name); } @@ -37,7 +37,7 @@ void CommonObjects::loadScriptComponents() const { if (script) { - script->loader.collectAll(this, true, script->root()); + script->load(this, true); script.reset(); } } diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp index 3d34d55..db256a9 100644 --- a/project2/common/scriptLoader.cpp +++ b/project2/common/scriptLoader.cpp @@ -117,7 +117,6 @@ LoaderBase::collectAll(ScriptNodePtr node, bool childrenOnly, const StorerPtrs & void LoaderBase::collectAll(const CommonObjects * co, bool childrenOnly, ScriptNodePtr node) { - (void)co; addLoadTarget(node, Storer::into<ElementLoader>(&libraries)); if (depth != 0 && co) { throw std::logic_error("Cannot set CommonObjects in subloader"); @@ -147,6 +146,10 @@ LoaderBase::onAllComponents(const boost::function1<void, ComponentLoader *> & fu } } +ComponentLoader::~ComponentLoader() +{ +} + void ComponentLoader::onBegin() { diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h index 6878983..b187ebb 100644 --- a/project2/common/scriptLoader.h +++ b/project2/common/scriptLoader.h @@ -114,6 +114,7 @@ class LoaderBase { class Options; class ComponentLoader { public: + virtual ~ComponentLoader() = 0; virtual void onBegin(); // App engine start up (before settings are processed) virtual void onBefore(); // Before the app engine processes a request (after settings are processed) virtual void onIdle(); // When the app engine goes idle diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp index 65a1ed0..4e9f18b 100644 --- a/project2/common/scripts.cpp +++ b/project2/common/scripts.cpp @@ -40,3 +40,8 @@ ScriptNode::applyValue(const Glib::ustring & n, VariableType & target) const } } +void +ScriptReader::load(const CommonObjects * co, bool childrenOnly) const +{ + loader.collectAll(co, childrenOnly, root()); +} diff --git a/project2/common/scripts.h b/project2/common/scripts.h index 3469d4a..497ea6d 100644 --- a/project2/common/scripts.h +++ b/project2/common/scripts.h @@ -17,7 +17,7 @@ SimpleMessage2Exception(DependencyNotFound); class ScriptNode; class ScriptReader; typedef boost::intrusive_ptr<const ScriptNode> ScriptNodePtr; -typedef boost::intrusive_ptr<ScriptReader> ScriptReaderPtr; +typedef boost::intrusive_ptr<const ScriptReader> ScriptReaderPtr; class ScriptNode : public IntrusivePtrBase { public: @@ -51,8 +51,9 @@ class ScriptNode : public IntrusivePtrBase { class ScriptReader : public virtual IntrusivePtrBase { public: - virtual ScriptNodePtr root() = 0; - LoaderBase loader; + virtual ScriptNodePtr root() const = 0; + virtual void load(const CommonObjects *, bool childrenOnly) const; + mutable LoaderBase loader; }; /// Base class to implement script reader modules diff --git a/project2/uuid/uuid.cpp b/project2/uuid/uuid.cpp index ddc0e50..0d864b5 100644 --- a/project2/uuid/uuid.cpp +++ b/project2/uuid/uuid.cpp @@ -29,9 +29,7 @@ UUID::UUID(const std::string & str) UUID UUID::generate_random() { - UUID u; - u._uuid = new boost::uuids::uuid(boost::uuids::random_generator()()); - return u; + return UUID(new boost::uuids::uuid(boost::uuids::random_generator()())); } bool @@ -79,9 +77,7 @@ UUID::UUID(const std::string & str) UUID UUID::generate_random() { - UUID u; - u._uuid->make(UUID_MAKE_V4); - return u; + return UUID(_uuid->make(UUID_MAKE_V4)); } bool @@ -114,6 +110,11 @@ UUID::~UUID() delete _uuid; } +UUID::UUID(uuid_impl * u) +{ + _uuid = u; +} + bool UUID::operator!=(const UUID & other) const { diff --git a/project2/uuid/uuid.h b/project2/uuid/uuid.h index 0712f8f..76d812d 100644 --- a/project2/uuid/uuid.h +++ b/project2/uuid/uuid.h @@ -11,6 +11,7 @@ class UUID { public: UUID(); ~UUID(); + UUID(uuid_impl * _uuid); UUID(const UUID &); UUID(const std::string &); diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp index fc62a6b..62cedcb 100644 --- a/project2/xml/xmlScriptParser.cpp +++ b/project2/xml/xmlScriptParser.cpp @@ -22,13 +22,21 @@ XmlScriptParser::XmlScriptParser(const boost::filesystem::path & file) } ScriptNodePtr -XmlScriptParser::root() { +XmlScriptParser::root() const +{ if (!_root) { _root = new XmlScriptNode(get_document()->get_root_node(), this); } return _root; } +void +XmlScriptParser::load(const CommonObjects * co, bool childrenOnly) const +{ + ScriptReader::load(co, childrenOnly); + _root.reset(); +} + class XmlScriptReaderLoader : public ScriptReaderLoader { public: ScriptReaderPtr resolveScript(const std::string & group, const std::string & name) const { diff --git a/project2/xml/xmlScriptParser.h b/project2/xml/xmlScriptParser.h index 452f0ef..39e27bc 100644 --- a/project2/xml/xmlScriptParser.h +++ b/project2/xml/xmlScriptParser.h @@ -38,9 +38,10 @@ class XmlScriptParser : public xmlpp::DomParser, public ScriptReader { SimpleMessageExceptionBase(IncludesError, ParseError); XmlScriptParser(const boost::filesystem::path & file); - ScriptNodePtr root(); + ScriptNodePtr root() const; + void load(const CommonObjects *, bool childrenOnly) const; private: - ScriptNodePtr _root; + mutable ScriptNodePtr _root; }; |