mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
couple of memory leaks fixes.
This commit is contained in:
parent
1be3894e6f
commit
48b3bb980d
@ -285,6 +285,10 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
|
|||||||
|
|
||||||
if (c == LUA_SIGNATURE[0]) {
|
if (c == LUA_SIGNATURE[0]) {
|
||||||
lua_pushliteral(L, "Bytecode prohibited when mod security is enabled.");
|
lua_pushliteral(L, "Bytecode prohibited when mod security is enabled.");
|
||||||
|
std::fclose(fp);
|
||||||
|
if (path) {
|
||||||
|
delete [] chunk_name;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +299,15 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
|
|||||||
size_t size = std::ftell(fp) - start;
|
size_t size = std::ftell(fp) - start;
|
||||||
char *code = new char[size];
|
char *code = new char[size];
|
||||||
ret = std::fseek(fp, start, SEEK_SET);
|
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);
|
size_t num_read = std::fread(code, 1, size, fp);
|
||||||
if (path) {
|
if (path) {
|
||||||
@ -303,6 +315,10 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
|
|||||||
}
|
}
|
||||||
if (num_read != size) {
|
if (num_read != size) {
|
||||||
lua_pushliteral(L, "Error reading file to load.");
|
lua_pushliteral(L, "Error reading file to load.");
|
||||||
|
delete [] code;
|
||||||
|
if (path) {
|
||||||
|
delete [] chunk_name;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +144,7 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
|
|||||||
ov_clear(oggFile);
|
ov_clear(oggFile);
|
||||||
infostream << "Audio: Error decoding "
|
infostream << "Audio: Error decoding "
|
||||||
<< filename_for_logging << std::endl;
|
<< filename_for_logging << std::endl;
|
||||||
|
delete snd;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,8 +75,10 @@ std::string read_file_to_string(const std::string &filepath)
|
|||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
|
|
||||||
long filesize = ftell(f);
|
long filesize = ftell(f);
|
||||||
if (filesize == -1)
|
if (filesize == -1) {
|
||||||
|
fclose(f);
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
rewind(f);
|
rewind(f);
|
||||||
|
|
||||||
buf.resize(filesize);
|
buf.resize(filesize);
|
||||||
|
@ -95,6 +95,7 @@ void AreaStore::deserialize(std::istream &is)
|
|||||||
is.read(data, data_len);
|
is.read(data, data_len);
|
||||||
a.data = std::string(data, data_len);
|
a.data = std::string(data, data_len);
|
||||||
insertArea(&a);
|
insertArea(&a);
|
||||||
|
delete [] data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +542,7 @@ static SRP_Result fill_buff()
|
|||||||
|
|
||||||
if (!fp) return SRP_ERR;
|
if (!fp) return SRP_ERR;
|
||||||
|
|
||||||
if (fread(g_rand_buff, sizeof(g_rand_buff), 1, fp) != 1) return SRP_ERR;
|
if (fread(g_rand_buff, sizeof(g_rand_buff), 1, fp) != 1) { fclose(fp); return SRP_ERR; }
|
||||||
if (fclose(fp)) return SRP_ERR;
|
if (fclose(fp)) return SRP_ERR;
|
||||||
#endif
|
#endif
|
||||||
return SRP_OK;
|
return SRP_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user