forked from mia/Aegisub
Fix a bunch of memory leaks reported by valgrind and msvc about the registered factories never being cleared.
Originally committed to SVN as r2951.
This commit is contained in:
parent
9891c28977
commit
392fbdfa4d
13 changed files with 132 additions and 17 deletions
|
@ -181,6 +181,13 @@ void AudioPlayerFactoryManager::RegisterProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Clear all factories
|
||||||
|
void AudioPlayerFactoryManager::ClearProviders() {
|
||||||
|
ClearFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// Static
|
// Static
|
||||||
template <class AudioPlayerFactory> std::map<wxString,AudioPlayerFactory*>* FactoryManager<AudioPlayerFactory>::factories=NULL;
|
template <class AudioPlayerFactory> std::map<wxString,AudioPlayerFactory*>* FactoryManager<AudioPlayerFactory>::factories=NULL;
|
||||||
|
|
|
@ -59,6 +59,7 @@ class AudioPlayerFactoryManager : public FactoryManager<AudioPlayerFactory> {
|
||||||
public:
|
public:
|
||||||
static AudioPlayer *GetAudioPlayer();
|
static AudioPlayer *GetAudioPlayer();
|
||||||
static void RegisterProviders();
|
static void RegisterProviders();
|
||||||
|
static void ClearProviders();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -288,6 +288,13 @@ void AudioProviderFactoryManager::RegisterProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Clear all providers
|
||||||
|
void AudioProviderFactoryManager::ClearProviders() {
|
||||||
|
ClearFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// Static
|
// Static
|
||||||
template <class AudioProviderFactory> std::map<wxString,AudioProviderFactory*>* FactoryManager<AudioProviderFactory>::factories=NULL;
|
template <class AudioProviderFactory> std::map<wxString,AudioProviderFactory*>* FactoryManager<AudioProviderFactory>::factories=NULL;
|
||||||
|
|
|
@ -51,4 +51,5 @@ class AudioProviderFactoryManager : public FactoryManager<AudioProviderFactory>
|
||||||
public:
|
public:
|
||||||
static void RegisterProviders();
|
static void RegisterProviders();
|
||||||
static AudioProvider *GetAudioProvider(wxString filename, int cache=-1);
|
static AudioProvider *GetAudioProvider(wxString filename, int cache=-1);
|
||||||
|
static void ClearProviders();
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,6 +52,17 @@ protected:
|
||||||
// Static map of all factories
|
// Static map of all factories
|
||||||
static std::map<wxString,T*> *factories;
|
static std::map<wxString,T*> *factories;
|
||||||
|
|
||||||
|
static void ClearFactories() {
|
||||||
|
if (factories && !factories->empty()) {
|
||||||
|
typename std::map<wxString,T*>::iterator iter;
|
||||||
|
for (iter = factories->begin(); iter != factories->end(); iter++) {
|
||||||
|
delete iter->second;
|
||||||
|
}
|
||||||
|
factories->clear();
|
||||||
|
}
|
||||||
|
delete factories;
|
||||||
|
}
|
||||||
|
|
||||||
// Register one factory type (with possible subtypes)
|
// Register one factory type (with possible subtypes)
|
||||||
static void RegisterFactory(T* factory,wxString name, wxArrayString subTypes=wxArrayString()) {
|
static void RegisterFactory(T* factory,wxString name, wxArrayString subTypes=wxArrayString()) {
|
||||||
// Create factories if it doesn't exist
|
// Create factories if it doesn't exist
|
||||||
|
@ -91,7 +102,9 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Virtual destructor
|
// Virtual destructor
|
||||||
virtual ~FactoryManager() {}
|
virtual ~FactoryManager() {
|
||||||
|
ClearFactories();
|
||||||
|
};
|
||||||
|
|
||||||
// Get list of all factories, with favourite as first
|
// Get list of all factories, with favourite as first
|
||||||
static wxArrayString GetFactoryList(wxString favourite=_T("")) {
|
static wxArrayString GetFactoryList(wxString favourite=_T("")) {
|
||||||
|
|
|
@ -44,30 +44,66 @@
|
||||||
#include "audio_player_manager.h"
|
#include "audio_player_manager.h"
|
||||||
#include "subtitles_provider_manager.h"
|
#include "subtitles_provider_manager.h"
|
||||||
#include "spellchecker_manager.h"
|
#include "spellchecker_manager.h"
|
||||||
#ifdef WITH_AUTO4_LUA
|
|
||||||
#include "auto4_lua_factory.h"
|
|
||||||
#endif
|
|
||||||
#ifdef WITH_PERL
|
|
||||||
#include "auto4_perl_factory.h"
|
|
||||||
#endif
|
|
||||||
#ifdef WITH_AUTO3
|
|
||||||
#include "auto4_auto3_factory.h"
|
|
||||||
#endif
|
|
||||||
#ifdef WITH_RUBY
|
|
||||||
#include "auto4_ruby_factory.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
PluginManager::PluginManager() {
|
PluginManager::PluginManager() {
|
||||||
init = false;
|
init = false;
|
||||||
|
|
||||||
|
#ifdef WITH_AUTO4_LUA
|
||||||
|
lua = NULL;
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_PERL
|
||||||
|
perl = NULL;
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_AUTO3
|
||||||
|
auto3 = NULL;
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_RUBY
|
||||||
|
ruby = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
// Destructor
|
// Destructor
|
||||||
PluginManager::~PluginManager() {
|
PluginManager::~PluginManager() {
|
||||||
|
VideoProviderFactoryManager::ClearProviders();
|
||||||
|
AudioProviderFactoryManager::ClearProviders();
|
||||||
|
AudioPlayerFactoryManager::ClearProviders();
|
||||||
|
SubtitlesProviderFactoryManager::ClearProviders();
|
||||||
|
SpellCheckerFactoryManager::ClearProviders();
|
||||||
|
|
||||||
|
#ifdef WITH_AUTO4_LUA
|
||||||
|
if (lua) {
|
||||||
|
lua->Unregister(lua);
|
||||||
|
delete lua;
|
||||||
|
lua = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_PERL
|
||||||
|
if (perl) {
|
||||||
|
perl->Unregister(perl);
|
||||||
|
delete perl;
|
||||||
|
perl = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_AUTO3
|
||||||
|
if (auto3) {
|
||||||
|
auto3->Unregister(auto3);
|
||||||
|
delete auto3;
|
||||||
|
auto3 = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_RUBY
|
||||||
|
if (ruby) {
|
||||||
|
ruby->Unregister(ruby);
|
||||||
|
delete ruby;
|
||||||
|
ruby = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,18 +120,18 @@ void PluginManager::RegisterBuiltInPlugins() {
|
||||||
|
|
||||||
// Automation languages
|
// Automation languages
|
||||||
#ifdef WITH_AUTO4_LUA
|
#ifdef WITH_AUTO4_LUA
|
||||||
Automation4::LuaScriptFactory *lua = new Automation4::LuaScriptFactory();
|
lua = new Automation4::LuaScriptFactory();
|
||||||
lua->RegisterFactory();
|
lua->RegisterFactory();
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_PERL
|
#ifdef WITH_PERL
|
||||||
Automation4::PerlScriptFactory *perl = new Automation4::PerlScriptFactory();
|
perl = new Automation4::PerlScriptFactory();
|
||||||
perl->RegisterFactory();
|
perl->RegisterFactory();
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_AUTO3
|
#ifdef WITH_AUTO3
|
||||||
new Automation4::Auto3ScriptFactory();
|
auto3 = new Automation4::Auto3ScriptFactory();
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_RUBY
|
#ifdef WITH_RUBY
|
||||||
new Automation4::RubyScriptFactory();
|
ruby = new Automation4::RubyScriptFactory();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,19 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef WITH_AUTO4_LUA
|
||||||
|
#include "auto4_lua_factory.h"
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_PERL
|
||||||
|
#include "auto4_perl_factory.h"
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_AUTO3
|
||||||
|
#include "auto4_auto3_factory.h"
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_RUBY
|
||||||
|
#include "auto4_ruby_factory.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// Plugin manager class
|
// Plugin manager class
|
||||||
|
@ -43,6 +56,19 @@ class PluginManager {
|
||||||
private:
|
private:
|
||||||
bool init;
|
bool init;
|
||||||
|
|
||||||
|
#ifdef WITH_AUTO4_LUA
|
||||||
|
Automation4::LuaScriptFactory *lua;
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_PERL
|
||||||
|
Automation4::PerlScriptFactory *perl;
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_AUTO3
|
||||||
|
Automation4::Auto3ScriptFactory *auto3;
|
||||||
|
#endif
|
||||||
|
#ifdef WITH_RUBY
|
||||||
|
Automation4::RubyScriptFactory *ruby;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PluginManager();
|
PluginManager();
|
||||||
~PluginManager();
|
~PluginManager();
|
||||||
|
|
|
@ -80,6 +80,13 @@ void SpellCheckerFactoryManager::RegisterProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Clear all providers
|
||||||
|
void SpellCheckerFactoryManager::ClearProviders() {
|
||||||
|
ClearFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// Static
|
// Static
|
||||||
template <class SpellCheckerFactory> std::map<wxString,SpellCheckerFactory*>* FactoryManager<SpellCheckerFactory>::factories=NULL;
|
template <class SpellCheckerFactory> std::map<wxString,SpellCheckerFactory*>* FactoryManager<SpellCheckerFactory>::factories=NULL;
|
||||||
|
|
|
@ -50,4 +50,5 @@ class SpellCheckerFactoryManager : public FactoryManager<SpellCheckerFactory> {
|
||||||
public:
|
public:
|
||||||
static SpellChecker *GetSpellChecker();
|
static SpellChecker *GetSpellChecker();
|
||||||
static void RegisterProviders();
|
static void RegisterProviders();
|
||||||
|
static void ClearProviders();
|
||||||
};
|
};
|
||||||
|
|
|
@ -107,6 +107,13 @@ void SubtitlesProviderFactoryManager::RegisterProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
// Clear providers
|
||||||
|
void SubtitlesProviderFactoryManager::ClearProviders() {
|
||||||
|
ClearFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// Static
|
// Static
|
||||||
template <class SubtitlesProviderFactory> std::map<wxString,SubtitlesProviderFactory*>* FactoryManager<SubtitlesProviderFactory>::factories=NULL;
|
template <class SubtitlesProviderFactory> std::map<wxString,SubtitlesProviderFactory*>* FactoryManager<SubtitlesProviderFactory>::factories=NULL;
|
||||||
|
|
|
@ -51,6 +51,7 @@ class SubtitlesProviderFactoryManager : public FactoryManager<SubtitlesProviderF
|
||||||
public:
|
public:
|
||||||
static SubtitlesProvider *GetProvider();
|
static SubtitlesProvider *GetProvider();
|
||||||
static void RegisterProviders();
|
static void RegisterProviders();
|
||||||
|
static void ClearProviders();
|
||||||
static bool ProviderAvailable();
|
static bool ProviderAvailable();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,13 @@ void VideoProviderFactoryManager::RegisterProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Clear all providers
|
||||||
|
void VideoProviderFactoryManager::ClearProviders() {
|
||||||
|
ClearFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// Static
|
// Static
|
||||||
template <class VideoProviderFactory> std::map<wxString,VideoProviderFactory*>* FactoryManager<VideoProviderFactory>::factories=NULL;
|
template <class VideoProviderFactory> std::map<wxString,VideoProviderFactory*>* FactoryManager<VideoProviderFactory>::factories=NULL;
|
||||||
|
|
|
@ -51,4 +51,5 @@ class VideoProviderFactoryManager : public FactoryManager<VideoProviderFactory>
|
||||||
public:
|
public:
|
||||||
static void RegisterProviders();
|
static void RegisterProviders();
|
||||||
static VideoProvider *GetProvider(wxString video,double fps=0.0);
|
static VideoProvider *GetProvider(wxString video,double fps=0.0);
|
||||||
|
static void ClearProviders();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue