diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-18 11:12:42 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-18 11:12:42 +0000 |
commit | d415ba2e8c64e3f8c767fcf56f25a041574704c6 (patch) | |
tree | 192ce17a81ed00a09670f90a33e967dc7eacd17e | |
parent | 546ae9ed020aefae6ee7470a92dff4901eceb53f (diff) | |
download | mana-client-d415ba2e8c64e3f8c767fcf56f25a041574704c6.tar.gz mana-client-d415ba2e8c64e3f8c767fcf56f25a041574704c6.tar.bz2 mana-client-d415ba2e8c64e3f8c767fcf56f25a041574704c6.tar.xz mana-client-d415ba2e8c64e3f8c767fcf56f25a041574704c6.zip |
Fixed double-free of true-type resources.
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/gui/truetypefont.cpp | 7 |
2 files changed, 6 insertions, 2 deletions
@@ -3,6 +3,7 @@ * src/beingmanager.h, src/beingmanager.cpp, src/net/beinghandler.cpp: Removed guess of being type from class number. Factored handler for new beings. + * src/gui/truetypefont.cpp: Fixed double-free of true-type resources. 2007-10-15 Bjørn Lindeijer <bjorn@lindeijer.nl> diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 7ef29539..bba268c7 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -82,15 +82,17 @@ class TextChunk static std::list<TextChunk> cache; typedef std::list<TextChunk>::iterator CacheIterator; +static int fontCounter; TrueTypeFont::TrueTypeFont(const std::string& filename, int size) { - if (!TTF_WasInit() && TTF_Init() == -1) + if (fontCounter == 0 && TTF_Init() == -1) { throw GCN_EXCEPTION("Unable to initialize SDL_ttf: " + std::string(TTF_GetError())); } + ++fontCounter; mFont = TTF_OpenFont(filename.c_str(), size); if (mFont == NULL) @@ -103,8 +105,9 @@ TrueTypeFont::TrueTypeFont(const std::string& filename, int size) TrueTypeFont::~TrueTypeFont() { TTF_CloseFont(mFont); + --fontCounter; - if (TTF_WasInit()) + if (fontCounter == 0) { TTF_Quit(); } |