diff --git a/src/iss/plugin/loader.cpp b/src/iss/plugin/loader.cpp index 5e578e5..04f2b14 100644 --- a/src/iss/plugin/loader.cpp +++ b/src/iss/plugin/loader.cpp @@ -56,13 +56,12 @@ #include "loader.h" using namespace iss::plugin; -std::unordered_map> loader::_cache; std::shared_ptr loader::get_data(const std::string& filepath) { if (filepath.empty()) throw std::invalid_argument("failed to bind to loader: filepath was empty"); - auto iter = _cache.find(filepath); - if (iter != _cache.end()) + auto iter = get_cache().find(filepath); + if (iter != get_cache().end()) return iter->second; #if OS_IS_WINDOWS auto handle = (void*)LoadLibrary(filepath.c_str()); @@ -80,7 +79,7 @@ std::shared_ptr loader::get_data(const std::string& filepat + std::string(dlerror())); #endif auto data = std::make_shared(handle, filepath); - _cache[filepath] = data; + get_cache()[filepath] = data; return data; } diff --git a/src/iss/plugin/loader.h b/src/iss/plugin/loader.h index 68b8189..a5bbc33 100644 --- a/src/iss/plugin/loader.h +++ b/src/iss/plugin/loader.h @@ -111,6 +111,7 @@ class loader { : handle(handle), filepath(filepath) { } ~plugin_data() { + symbols.clear(); if (handle) { #if OS_IS_WINDOWS FreeLibrary((HINSTANCE)handle); @@ -122,7 +123,11 @@ class loader { }; private: // members - static std::unordered_map> _cache; + using cache_t = std::unordered_map>; + static cache_t& get_cache() { + static cache_t cache; + return cache; + } std::shared_ptr _data; std::shared_ptr get_data(const std::string &filepath); @@ -141,7 +146,7 @@ class loader { } loader(const loader &other) - : _data(_cache[other.filepath()]) { + : _data(get_cache()[other.filepath()]) { } void bind_function(const std::string &label); @@ -176,7 +181,7 @@ class loader { } inline loader& operator=(const loader &other) { - _data = _cache[other.filepath()]; + _data = get_cache()[other.filepath()]; return *this; }