aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2016-07-28 08:56:22 +0100
committerLoic Blot <loic.blot@unix-experience.fr>2016-08-10 16:59:32 +0200
commit48b3bb980d4a026d32739acc1982f16e3c303c5b (patch)
tree1685d44bb69642771a9840171bcab93a68f6da49 /src/script
parent1be3894e6f283b0538a725bc438922c7d7ec294a (diff)
downloadminetest-48b3bb980d4a026d32739acc1982f16e3c303c5b.tar.gz
minetest-48b3bb980d4a026d32739acc1982f16e3c303c5b.tar.bz2
minetest-48b3bb980d4a026d32739acc1982f16e3c303c5b.zip
couple of memory leaks fixes.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_security.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp
index e117a4811..0e64c4c61 100644
--- a/src/script/cpp_api/s_security.cpp
+++ b/src/script/cpp_api/s_security.cpp
@@ -285,6 +285,10 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
if (c == LUA_SIGNATURE[0]) {
lua_pushliteral(L, "Bytecode prohibited when mod security is enabled.");
+ std::fclose(fp);
+ if (path) {
+ delete [] chunk_name;
+ }
return false;
}
@@ -295,7 +299,15 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
size_t size = std::ftell(fp) - start;
char *code = new char[size];
ret = std::fseek(fp, start, SEEK_SET);
- CHECK_FILE_ERR(ret, fp);
+ if (ret) {
+ lua_pushfstring(L, "%s: %s", path, strerror(errno));
+ std::fclose(fp);
+ delete [] code;
+ if (path) {
+ delete [] chunk_name;
+ }
+ return false;
+ }
size_t num_read = std::fread(code, 1, size, fp);
if (path) {
@@ -303,6 +315,10 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
}
if (num_read != size) {
lua_pushliteral(L, "Error reading file to load.");
+ delete [] code;
+ if (path) {
+ delete [] chunk_name;
+ }
return false;
}