# HG changeset patch # User cannam # Date 1196686647 0 # Node ID 896a97349ac5c311c6b461cb6352ad72048f40e5 # Parent ca44b3594d2e6ec665a627a8c8f5231f9fca990e * Add a static wrapper object to wrap the static instance pointer, so that it can be properly deleted on program exit instead of showing up in certain tools as leaked diff -r ca44b3594d2e -r 896a97349ac5 vamp-sdk/hostext/PluginLoader.cpp --- a/vamp-sdk/hostext/PluginLoader.cpp Sun Nov 18 10:53:54 2007 +0000 +++ b/vamp-sdk/hostext/PluginLoader.cpp Mon Dec 03 12:57:27 2007 +0000 @@ -86,6 +86,8 @@ string getLibraryPathForPlugin(PluginKey key); + static void setInstanceToClean(PluginLoader *instance); + protected: class PluginDeletionNotifyAdapter : public PluginWrapper { public: @@ -95,6 +97,15 @@ Impl *m_loader; }; + class InstanceCleaner { + public: + InstanceCleaner() : m_instance(0) { } + ~InstanceCleaner() { delete m_instance; } + void setInstance(PluginLoader *instance) { m_instance = instance; } + protected: + PluginLoader *m_instance; + }; + virtual void pluginDeleted(PluginDeletionNotifyAdapter *adapter); map m_pluginLibraryNameMap; @@ -115,11 +126,16 @@ string splicePath(string a, string b); vector listFiles(string dir, string ext); + + static InstanceCleaner m_cleaner; }; PluginLoader * PluginLoader::m_instance = 0; +PluginLoader::Impl::InstanceCleaner +PluginLoader::Impl::m_cleaner; + PluginLoader::PluginLoader() { m_impl = new Impl(); @@ -133,7 +149,13 @@ PluginLoader * PluginLoader::getInstance() { - if (!m_instance) m_instance = new PluginLoader(); + if (!m_instance) { + // The cleaner doesn't own the instance, because we leave the + // instance pointer in the base class for binary backwards + // compatibility reasons and to avoid waste + m_instance = new PluginLoader(); + Impl::setInstanceToClean(m_instance); + } return m_instance; } @@ -178,6 +200,12 @@ { } +void +PluginLoader::Impl::setInstanceToClean(PluginLoader *instance) +{ + m_cleaner.setInstance(instance); +} + vector PluginLoader::Impl::listPlugins() {