diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp
index e117a4811f440b3dda30dd02ab8e27f5b4c61128..0e64c4c61e3720c82ea2c5e51da7d549de5b8523 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;
 	}
 
diff --git a/src/sound_openal.cpp b/src/sound_openal.cpp
index e2b6d937accfedbafeaf1dfe0b863b9b9b9afbb1..1832a0c77a327640249db71373c5de2e99d0890c 100644
--- a/src/sound_openal.cpp
+++ b/src/sound_openal.cpp
@@ -144,6 +144,7 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
 			ov_clear(oggFile);
 			infostream << "Audio: Error decoding "
 				<< filename_for_logging << std::endl;
+			delete snd;
 			return NULL;
 		}
 
diff --git a/src/unittest/test_map_settings_manager.cpp b/src/unittest/test_map_settings_manager.cpp
index 9292bf87c8e14697870ff22fe2c1d196ef976d7d..4f5ac80f2a08cd15d24b5180b6b90e1f280bf416 100644
--- a/src/unittest/test_map_settings_manager.cpp
+++ b/src/unittest/test_map_settings_manager.cpp
@@ -75,8 +75,10 @@ std::string read_file_to_string(const std::string &filepath)
 	fseek(f, 0, SEEK_END);
 
 	long filesize = ftell(f);
-	if (filesize == -1)
+	if (filesize == -1) {
+		fclose(f);
 		return "";
+	}
 	rewind(f);
 
 	buf.resize(filesize);
diff --git a/src/util/areastore.cpp b/src/util/areastore.cpp
index 58f08a8c2e22918cdce829b1a45c5340177054fe..cef67da2ce243378e24f7ba3b857ce7c09c25938 100644
--- a/src/util/areastore.cpp
+++ b/src/util/areastore.cpp
@@ -95,6 +95,7 @@ void AreaStore::deserialize(std::istream &is)
 		is.read(data, data_len);
 		a.data = std::string(data, data_len);
 		insertArea(&a);
+		delete [] data;
 	}
 }
 
diff --git a/src/util/srp.cpp b/src/util/srp.cpp
index 0d3c938a3a593bb6a244e57ba429153e8e1f2937..77c1816e8a5d9f6d8dbbe147d776d6cb078d814b 100644
--- a/src/util/srp.cpp
+++ b/src/util/srp.cpp
@@ -542,7 +542,7 @@ static SRP_Result fill_buff()
 
 	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;
 #endif
 	return SRP_OK;