Fix potential memory leaks

This commit is contained in:
Maschell 2021-01-01 01:59:09 +01:00
parent 096ef0c94a
commit ec443161af
2 changed files with 5 additions and 1 deletions

View File

@ -128,7 +128,9 @@ public:
return false; return false;
} }
return load(stream); auto res = load(stream);
stream.close();
return res;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -76,6 +76,7 @@ std::optional<PluginData> PluginDataFactory::load(const std::string &filename, M
// reading into a 0x40 aligned buffer increases reading speed. // reading into a 0x40 aligned buffer increases reading speed.
char *data = (char *) memalign(0x40, length); char *data = (char *) memalign(0x40, length);
if (!data) { if (!data) {
is.close();
DEBUG_FUNCTION_LINE("Failed to alloc memory for holding the plugin"); DEBUG_FUNCTION_LINE("Failed to alloc memory for holding the plugin");
return {}; return {};
} }
@ -85,6 +86,7 @@ std::optional<PluginData> PluginDataFactory::load(const std::string &filename, M
result.resize(length); result.resize(length);
memcpy(&result[0], data, length); memcpy(&result[0], data, length);
free(data); free(data);
is.close();
DEBUG_FUNCTION_LINE("Loaded file!"); DEBUG_FUNCTION_LINE("Loaded file!");