summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-11-24 15:25:41 +0000
committerrubidium <rubidium@openttd.org>2013-11-24 15:25:41 +0000
commitc54a70cce81e382c43d085988f0762f60b6a19da (patch)
treef9b31d50696b760bde9d4008ec25b752f8dec11f /src/game
parent0ac9ed0b6b97885a99eb1dc3c9e5e12458bc2055 (diff)
downloadopenttd-c54a70cce81e382c43d085988f0762f60b6a19da.tar.xz
(svn r26090) -Fix: leaking of file descriptor when reading strings for game texts
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game_text.cpp10
1 files 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;
}