File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,16 @@ namespace fs = std::filesystem;
1515namespace cudaq ::qec {
1616
1717static std::map<std::string, PluginHandle> &get_plugin_handles () {
18- static std::map<std::string, PluginHandle> plugin_handles;
19- return plugin_handles;
18+ // Formerly this code was like this:
19+ // static std::map<std::string, PluginHandle> plugin_handles;
20+ // return plugin_handles;
21+ // But that created a double free error when the program exited.
22+ // This was because the static destructor for the map was called first,
23+ // and then the cleanup_plugins function was called which tried to access the
24+ // already destroyed map. This new approach does create a small memory leak,
25+ // but it prevents the double free error.
26+ static auto *plugin_handles = new std::map<std::string, PluginHandle>();
27+ return *plugin_handles; // Dereference pointer to return reference
2028}
2129
2230// Function to load plugins from a directory based on their type
You can’t perform that action at this time.
0 commit comments