wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src font.cpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src font.cpp
Date: Sat, 08 Jan 2005 17:02:07 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    05/01/08 21:49:30

Modified files:
        src            : font.cpp 

Log message:
        Don't load the whole font in memory when we only want to assert its 
existence. Leak memory only when successful, not on error.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.96&tr2=1.97&r1=text&r2=text

Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.96 wesnoth/src/font.cpp:1.97
--- wesnoth/src/font.cpp:1.96   Sat Jan  8 21:09:16 2005
+++ wesnoth/src/font.cpp        Sat Jan  8 21:49:29 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.96 2005/01/08 21:09:16 ydirson Exp $ */
+/* $Id: font.cpp,v 1.97 2005/01/08 21:49:29 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -54,10 +54,10 @@
                name = game_config::path + "/fonts/" + fname;
                LOG_FT << "Trying file '" << name << "' ...\n";
 
-               if(read_file(name).empty()) {
+               if (!file_exists(name)) {
                        name = "fonts/" + fname;
                        WRN_FT << "Failed opening '" << name << "'; now trying 
'" << name << "' ...\n";
-                       if(read_file(name).empty()) {
+                       if (!file_exists(name)) {
                                ERR_FT << "Failed opening font: " << fname << 
"\n";
                                return NULL;
                        }
@@ -66,7 +66,7 @@
                name = "fonts/" + fname;
                LOG_FT << "Trying file '" << name << "' ...\n";
 
-               if(read_file(name).empty()) {
+               if(!file_exists(name)) {
                        ERR_FT << "Failed opening font '" << fname << "'\n";
                        return NULL;
                }
@@ -76,11 +76,13 @@
 
        TTF_Font* font = TTF_OpenFont(name.c_str(),size);
 #else
-       std::string *s = new std::string(read_file("fonts/" + fname));
-       if (s->empty()) {
+       std::string tmp = read_file("fonts/" + fname);
+       if (tmp.empty()) {
                ERR_FT << "Failed opening font file '" << fname << "'\n";
                return NULL;
        }
+       // the following statement would leak memory if fonts were closed
+       std::string *s = new std::string(tmp);
        SDL_RWops* ops = SDL_RWFromMem((void*)s->c_str(), s->size());
        TTF_Font* font = TTF_OpenFontRW(ops, 0, size);
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]