From 2308748f01e5ef80c22bd489a218aeee85250aa3 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Fri, 12 Jun 2009 09:52:35 +0000 Subject: Made the DraciFont::freeFont() method safe to call in any circumstance by making it check for NULL pointers itself to prevent double free / corruption. This also fixes a potential bug in the destructor. svn-id: r41469 --- engines/draci/font.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/engines/draci/font.cpp b/engines/draci/font.cpp index 5ea46ddb17..a99dd06a58 100644 --- a/engines/draci/font.cpp +++ b/engines/draci/font.cpp @@ -59,10 +59,8 @@ DraciFont::~DraciFont() { bool DraciFont::setFont(Common::String &filename) { - // If there is a font already loaded, free it - if (_charData) { - freeFont(); - } + // Free previously loaded font (if any) + freeFont(); Common::File f; @@ -98,8 +96,11 @@ bool DraciFont::setFont(Common::String &filename) { } void DraciFont::freeFont() { - delete[] _charWidths; - delete[] _charData; + // If there is a font already loaded, free it + if (_charData) { + delete[] _charWidths; + delete[] _charData; + } } uint8 DraciFont::getCharWidth(uint8 chr) const { -- cgit v1.2.3