From 0dca1e1124026b21cd0d80fd30fc5d5dcac38054 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 13 May 2022 09:50:24 +0900 Subject: [PATCH] [plugin] Pull plugin from list before calling its shutdown This ensures that the plugin's shutdown function won't get called twice in the event of an error in the plugin's unload sequence triggering a second Sys_Shutdown, especially if the plugin is being unloaded as a part of another sub-system's shutdown sequence (which is probably in itself a design mistake, need to look into that). --- libs/util/plugin.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/util/plugin.c b/libs/util/plugin.c index 7f5ec18b9..366822d88 100644 --- a/libs/util/plugin.c +++ b/libs/util/plugin.c @@ -396,6 +396,11 @@ PI_LoadPlugin (const char *type, const char *name) VISIBLE qboolean PI_UnloadPlugin (plugin_t *plugin) { + // Remove the plugin from the set of loaded plugins to ensure that a + // shutdown triggered by an error in the unload process doesn't try to + // unload the plugin a second time + loaded_plugin_t *lp = Hash_Del (loaded_plugins, plugin->full_name); + if (plugin && plugin->functions && plugin->functions->general && plugin->functions->general->shutdown) { plugin->functions->general->shutdown (); @@ -405,8 +410,7 @@ PI_UnloadPlugin (plugin_t *plugin) plugin->type); } - // remove from the table of loaded plugins - Hash_Free (loaded_plugins, Hash_Del (loaded_plugins, plugin->full_name)); + Hash_Free (loaded_plugins, lp); if (!plugin->handle) // we didn't load it return true;