diff options
author | Johannes Schickel | 2012-05-03 13:45:40 -0700 |
---|---|---|
committer | Johannes Schickel | 2012-05-03 13:45:40 -0700 |
commit | b96143c1802b619553e476ad7a5a1eedeea0c768 (patch) | |
tree | b810d8cb6722c5d45082f2d73b9f59e40bc58154 | |
parent | e72f51129bfd11d0c926a2e21015a57740980928 (diff) | |
parent | 29e05ec05eb85cc1402ebee2c399a4a45bcd4933 (diff) | |
download | scummvm-rg350-b96143c1802b619553e476ad7a5a1eedeea0c768.tar.gz scummvm-rg350-b96143c1802b619553e476ad7a5a1eedeea0c768.tar.bz2 scummvm-rg350-b96143c1802b619553e476ad7a5a1eedeea0c768.zip |
Merge pull request #213 from fuzzie/leak-fixes
The pull request in question is "Memory leak fixes".
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.cpp | 5 | ||||
-rw-r--r-- | base/main.cpp | 14 | ||||
-rw-r--r-- | graphics/fontman.cpp | 36 | ||||
-rw-r--r-- | graphics/fontman.h | 5 | ||||
-rw-r--r-- | graphics/fonts/bdf.h | 2 | ||||
-rw-r--r-- | graphics/fonts/ttf.cpp | 4 | ||||
-rw-r--r-- | graphics/fonts/ttf.h | 2 |
7 files changed, 66 insertions, 2 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 45804b5d6e..cd820ae3b2 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -70,6 +70,11 @@ OpenGLGraphicsManager::~OpenGLGraphicsManager() { free(_gamePalette); free(_cursorPalette); + _screenData.free(); + _overlayData.free(); + _cursorData.free(); + _osdSurface.free(); + delete _gameTexture; delete _overlayTexture; delete _cursorTexture; diff --git a/base/main.cpp b/base/main.cpp index c657488758..25e1b881cc 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -55,6 +55,12 @@ #include "audio/mididrv.h" #include "audio/musicplugin.h" /* for music manager */ +#include "graphics/cursorman.h" +#include "graphics/fontman.h" +#ifdef USE_FREETYPE2 +#include "graphics/fonts/ttf.h" +#endif + #include "backends/keymapper/keymapper.h" #if defined(_WIN32_WCE) @@ -493,10 +499,18 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { PluginManager::destroy(); GUI::GuiManager::destroy(); Common::ConfigManager::destroy(); + Common::DebugManager::destroy(); + Common::EventRecorder::destroy(); Common::SearchManager::destroy(); #ifdef USE_TRANSLATION Common::TranslationManager::destroy(); #endif + MusicManager::destroy(); + Graphics::CursorManager::destroy(); + Graphics::FontManager::destroy(); +#ifdef USE_FREETYPE2 + Graphics::shutdownTTF(); +#endif return 0; } diff --git a/graphics/fontman.cpp b/graphics/fontman.cpp index 8d967d595f..99dd3d664f 100644 --- a/graphics/fontman.cpp +++ b/graphics/fontman.cpp @@ -47,6 +47,13 @@ FontManager::FontManager() { } FontManager::~FontManager() { + for (uint i = 0; i < _ownedFonts.size(); ++i) { + const Font *font = _ownedFonts[i]; + if (font == g_sysfont || font == g_sysfont_big || font == g_consolefont) + continue; + delete font; + } + delete g_sysfont; g_sysfont = 0; delete g_sysfont_big; @@ -90,6 +97,8 @@ bool FontManager::assignFontToName(const Common::String &name, const Font *font) Common::String lowercaseName = name; lowercaseName.toLowercase(); _fontMap[lowercaseName] = font; + if (Common::find(_ownedFonts.begin(), _ownedFonts.end(), font) == _ownedFonts.end()) + _ownedFonts.push_back(font); return true; } @@ -116,8 +125,35 @@ bool FontManager::setFont(FontUsage usage, const BdfFont *font) { void FontManager::removeFontName(const Common::String &name) { Common::String lowercaseName = name; lowercaseName.toLowercase(); + if (!_fontMap.contains(lowercaseName)) + return; + + const Font *font = _fontMap[lowercaseName]; _fontMap.erase(lowercaseName); + // Check if we still have a copy of this font in the map. + bool stillHasFont = false; + for (Common::HashMap<Common::String, const Font *>::iterator i = _fontMap.begin(); i != _fontMap.end(); ++i) { + if (i->_value != font) + continue; + stillHasFont = true; + break; + } + + if (!stillHasFont) { + // We don't have a copy of the font, so remove it from our list and delete it. + stillHasFont = true; + for (uint i = 0; i < _ownedFonts.size(); ++i) { + if (_ownedFonts[i] != font) + continue; + stillHasFont = false; + _ownedFonts.remove_at(i); + break; + } + assert(!stillHasFont); + delete font; + } + // In case the current localized font is removed, we fall back to the // default font again. if (_localizedFontName == lowercaseName) diff --git a/graphics/fontman.h b/graphics/fontman.h index 42f7d856fa..b06ddea860 100644 --- a/graphics/fontman.h +++ b/graphics/fontman.h @@ -60,7 +60,9 @@ public: const Font *getFontByName(const Common::String &name) const; /** - * Associates a font object with an 'name' + * Associates a font object with an 'name'. + * The FontManager takes ownership of the provided font object + * and will delete it when necesssary. * * @param name the name of the font * @param font the font object @@ -111,6 +113,7 @@ private: ~FontManager(); Common::HashMap<Common::String, const Font *> _fontMap; + Common::Array<const Font *> _ownedFonts; Common::String _localizedFontName; }; diff --git a/graphics/fonts/bdf.h b/graphics/fonts/bdf.h index 5b615cc043..b0166a2095 100644 --- a/graphics/fonts/bdf.h +++ b/graphics/fonts/bdf.h @@ -77,7 +77,7 @@ private: #define DEFINE_FONT(n) \ const BdfFont *n = 0; \ void create_##n() { \ - n = new BdfFont(desc, DisposeAfterUse::YES); \ + n = new BdfFont(desc, DisposeAfterUse::NO); \ } #define FORWARD_DECLARE_FONT(n) \ diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp index 7505f7913e..7f5c616710 100644 --- a/graphics/fonts/ttf.cpp +++ b/graphics/fonts/ttf.cpp @@ -70,6 +70,10 @@ private: bool _initialized; }; +void shutdownTTF() { + TTFLibrary::destroy(); +} + #define g_ttf ::Graphics::TTFLibrary::instance() TTFLibrary::TTFLibrary() : _library(), _initialized(false) { diff --git a/graphics/fonts/ttf.h b/graphics/fonts/ttf.h index 7222d6e112..ec7dbe04ef 100644 --- a/graphics/fonts/ttf.h +++ b/graphics/fonts/ttf.h @@ -34,6 +34,8 @@ namespace Graphics { class Font; Font *loadTTFFont(Common::SeekableReadStream &stream, int size, bool monochrome = false, const uint32 *mapping = 0); +void shutdownTTF(); + } // End of namespace Graphics #endif |