From ec443161af50b851bf8f944cf996d42bdccf88e9 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 1 Jan 2021 01:59:09 +0100 Subject: [PATCH] Fix potential memory leaks --- source/elfio/elfio.hpp | 4 +++- source/plugin/PluginDataFactory.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/source/elfio/elfio.hpp b/source/elfio/elfio.hpp index db3b6af..2a0174e 100644 --- a/source/elfio/elfio.hpp +++ b/source/elfio/elfio.hpp @@ -128,7 +128,9 @@ public: return false; } - return load(stream); + auto res = load(stream); + stream.close(); + return res; } //------------------------------------------------------------------------------ diff --git a/source/plugin/PluginDataFactory.cpp b/source/plugin/PluginDataFactory.cpp index 350fca4..d29d345 100644 --- a/source/plugin/PluginDataFactory.cpp +++ b/source/plugin/PluginDataFactory.cpp @@ -76,6 +76,7 @@ std::optional PluginDataFactory::load(const std::string &filename, M // reading into a 0x40 aligned buffer increases reading speed. char *data = (char *) memalign(0x40, length); if (!data) { + is.close(); DEBUG_FUNCTION_LINE("Failed to alloc memory for holding the plugin"); return {}; } @@ -85,6 +86,7 @@ std::optional PluginDataFactory::load(const std::string &filename, M result.resize(length); memcpy(&result[0], data, length); free(data); + is.close(); DEBUG_FUNCTION_LINE("Loaded file!");