aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Kasak2009-06-12 09:52:35 +0000
committerDenis Kasak2009-06-12 09:52:35 +0000
commit2308748f01e5ef80c22bd489a218aeee85250aa3 (patch)
tree04ec7db2a9a78fe35479a0a5304cae8644bdf0fa
parent51672df70002602eb09a6460259ac92960aeaf53 (diff)
downloadscummvm-rg350-2308748f01e5ef80c22bd489a218aeee85250aa3.tar.gz
scummvm-rg350-2308748f01e5ef80c22bd489a218aeee85250aa3.tar.bz2
scummvm-rg350-2308748f01e5ef80c22bd489a218aeee85250aa3.zip
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
-rw-r--r--engines/draci/font.cpp13
1 files 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 {