From c54a70cce81e382c43d085988f0762f60b6a19da Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 24 Nov 2013 15:25:41 +0000 Subject: (svn r26090) -Fix: leaking of file descriptor when reading strings for game texts --- src/game/game_text.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index 53c6795e9..cd9721b8a 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -81,9 +81,10 @@ LanguageStrings::~LanguageStrings() LanguageStrings *ReadRawLanguageStrings(const char *file) { LanguageStrings *ret = NULL; + FILE *fh = NULL; try { size_t to_read; - FILE *fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read); + fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read); if (fh == NULL) { return NULL; } @@ -96,7 +97,10 @@ LanguageStrings *ReadRawLanguageStrings(const char *file) } /* Check for invalid empty filename */ - if (*langname == '.' || *langname == 0) return NULL; + if (*langname == '.' || *langname == 0) { + fclose(fh); + return NULL; + } ret = new LanguageStrings(langname, strchr(langname, '.')); @@ -118,8 +122,10 @@ LanguageStrings *ReadRawLanguageStrings(const char *file) } } + fclose(fh); return ret; } catch (...) { + if (fh != NULL) fclose(fh); delete ret; return NULL; } -- cgit v1.2.3-70-g09d2