mirror of https://github.com/odrling/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
|
@ -181,6 +181,13 @@ void AudioPlayerFactoryManager::RegisterProviders() {
|
|||
}
|
||||
|
||||
|
||||
///////////////////////
|
||||
// Clear all factories
|
||||
void AudioPlayerFactoryManager::ClearProviders() {
|
||||
ClearFactories();
|
||||
}
|
||||
|
||||
|
||||
//////////
|
||||
// Static
|
||||
template <class AudioPlayerFactory> std::map<wxString,AudioPlayerFactory*>* FactoryManager<AudioPlayerFactory>::factories=NULL;
|
||||
|
|
|
@ -59,6 +59,7 @@ class AudioPlayerFactoryManager : public FactoryManager<AudioPlayerFactory> {
|
|||
public:
|
||||
static AudioPlayer *GetAudioPlayer();
|
||||
static void RegisterProviders();
|
||||
static void ClearProviders();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -288,6 +288,13 @@ void AudioProviderFactoryManager::RegisterProviders() {
|
|||
}
|
||||
|
||||
|
||||
///////////////////////
|
||||
// Clear all providers
|
||||
void AudioProviderFactoryManager::ClearProviders() {
|
||||
ClearFactories();
|
||||
}
|
||||
|
||||
|
||||
//////////
|
||||
// Static
|
||||
template <class AudioProviderFactory> std::map<wxString,AudioProviderFactory*>* FactoryManager<AudioProviderFactory>::factories=NULL;
|
||||
|
|
|
@ -51,4 +51,5 @@ class AudioProviderFactoryManager : public FactoryManager<AudioProviderFactory>
|
|||
public:
|
||||
static void RegisterProviders();
|
||||
static AudioProvider *GetAudioProvider(wxString filename, int cache=-1);
|
||||
static void ClearProviders();
|
||||
};
|
||||
|
|
|
@ -52,6 +52,17 @@ protected:
|
|||
// Static map of all 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)
|
||||
static void RegisterFactory(T* factory,wxString name, wxArrayString subTypes=wxArrayString()) {
|
||||
// Create factories if it doesn't exist
|
||||
|
@ -91,7 +102,9 @@ protected:
|
|||
|
||||
public:
|
||||
// Virtual destructor
|
||||
virtual ~FactoryManager() {}
|
||||
virtual ~FactoryManager() {
|
||||
ClearFactories();
|
||||
};
|
||||
|
||||
// Get list of all factories, with favourite as first
|
||||
static wxArrayString GetFactoryList(wxString favourite=_T("")) {
|
||||
|
|
|
@ -44,30 +44,66 @@
|
|||
#include "audio_player_manager.h"
|
||||
#include "subtitles_provider_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
|
||||
PluginManager::PluginManager() {
|
||||
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
|
||||
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
|
||||
#ifdef WITH_AUTO4_LUA
|
||||
Automation4::LuaScriptFactory *lua = new Automation4::LuaScriptFactory();
|
||||
lua = new Automation4::LuaScriptFactory();
|
||||
lua->RegisterFactory();
|
||||
#endif
|
||||
#ifdef WITH_PERL
|
||||
Automation4::PerlScriptFactory *perl = new Automation4::PerlScriptFactory();
|
||||
perl = new Automation4::PerlScriptFactory();
|
||||
perl->RegisterFactory();
|
||||
#endif
|
||||
#ifdef WITH_AUTO3
|
||||
new Automation4::Auto3ScriptFactory();
|
||||
auto3 = new Automation4::Auto3ScriptFactory();
|
||||
#endif
|
||||
#ifdef WITH_RUBY
|
||||
new Automation4::RubyScriptFactory();
|
||||
ruby = new Automation4::RubyScriptFactory();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,19 @@
|
|||
|
||||
#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
|
||||
|
@ -43,6 +56,19 @@ class PluginManager {
|
|||
private:
|
||||
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:
|
||||
PluginManager();
|
||||
~PluginManager();
|
||||
|
|
|
@ -80,6 +80,13 @@ void SpellCheckerFactoryManager::RegisterProviders() {
|
|||
}
|
||||
|
||||
|
||||
///////////////////////
|
||||
// Clear all providers
|
||||
void SpellCheckerFactoryManager::ClearProviders() {
|
||||
ClearFactories();
|
||||
}
|
||||
|
||||
|
||||
//////////
|
||||
// Static
|
||||
template <class SpellCheckerFactory> std::map<wxString,SpellCheckerFactory*>* FactoryManager<SpellCheckerFactory>::factories=NULL;
|
||||
|
|
|
@ -50,4 +50,5 @@ class SpellCheckerFactoryManager : public FactoryManager<SpellCheckerFactory> {
|
|||
public:
|
||||
static SpellChecker *GetSpellChecker();
|
||||
static void RegisterProviders();
|
||||
static void ClearProviders();
|
||||
};
|
||||
|
|
|
@ -107,6 +107,13 @@ void SubtitlesProviderFactoryManager::RegisterProviders() {
|
|||
}
|
||||
|
||||
|
||||
///////////////////
|
||||
// Clear providers
|
||||
void SubtitlesProviderFactoryManager::ClearProviders() {
|
||||
ClearFactories();
|
||||
}
|
||||
|
||||
|
||||
//////////
|
||||
// Static
|
||||
template <class SubtitlesProviderFactory> std::map<wxString,SubtitlesProviderFactory*>* FactoryManager<SubtitlesProviderFactory>::factories=NULL;
|
||||
|
|
|
@ -51,6 +51,7 @@ class SubtitlesProviderFactoryManager : public FactoryManager<SubtitlesProviderF
|
|||
public:
|
||||
static SubtitlesProvider *GetProvider();
|
||||
static void RegisterProviders();
|
||||
static void ClearProviders();
|
||||
static bool ProviderAvailable();
|
||||
};
|
||||
|
||||
|
|
|
@ -114,6 +114,13 @@ void VideoProviderFactoryManager::RegisterProviders() {
|
|||
}
|
||||
|
||||
|
||||
///////////////////////
|
||||
// Clear all providers
|
||||
void VideoProviderFactoryManager::ClearProviders() {
|
||||
ClearFactories();
|
||||
}
|
||||
|
||||
|
||||
//////////
|
||||
// Static
|
||||
template <class VideoProviderFactory> std::map<wxString,VideoProviderFactory*>* FactoryManager<VideoProviderFactory>::factories=NULL;
|
||||
|
|
|
@ -51,4 +51,5 @@ class VideoProviderFactoryManager : public FactoryManager<VideoProviderFactory>
|
|||
public:
|
||||
static void RegisterProviders();
|
||||
static VideoProvider *GetProvider(wxString video,double fps=0.0);
|
||||
static void ClearProviders();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue