From 97fb7026570f60bd3286c27e6049e19f08baa35e Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Thu, 18 Oct 2007 11:12:42 +0000 Subject: Fixed double-free of true-type resources. (cherry-picked from mainline) --- src/gui/truetypefont.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index bf95ca37..3986cca5 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -82,15 +82,17 @@ class TextChunk static std::list cache; typedef std::list::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(); } -- cgit v1.2.3-70-g09d2