summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-11-25 16:42:35 +0000
committerrubidium <rubidium@openttd.org>2013-11-25 16:42:35 +0000
commit43f76dcabbd64976eb830a525a4cd119b136ef3e (patch)
tree421640ef5a2327b623a2b54c38251ea712914e85
parentffb9279479252ce9ab018301d7d1f7cad7034979 (diff)
downloadopenttd-43f76dcabbd64976eb830a525a4cd119b136ef3e.tar.xz
(svn r26113) -Fix: unhandled seek error, and leaking file descriptor
-rw-r--r--src/script/squirrel.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index 89b0b5625..ce73f9a64 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -466,7 +466,10 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
switch (us) {
case SQ_BYTECODE_STREAM_TAG: { // BYTECODE
- fseek(file, -2, SEEK_CUR);
+ if (fseek(file, -2, SEEK_CUR) < 0) {
+ FioFCloseFile(file);
+ return sq_throwerror(vm, _SC("cannot seek the file"));
+ }
if (SQ_SUCCEEDED(sq_readclosure(vm, _io_file_read, &f))) {
FioFCloseFile(file);
return SQ_OK;
@@ -496,7 +499,8 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
default: // ASCII
func = _io_file_lexfeed_ASCII;
if (fseek(file, -2, SEEK_CUR) < 0) {
- return sq_throwerror(vm, _SC("cannot read the file"));
+ FioFCloseFile(file);
+ return sq_throwerror(vm, _SC("cannot seek the file"));
}
break;
}