diff options
Diffstat (limited to 'src/common/HPM.c')
-rw-r--r-- | src/common/HPM.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index a78f03daa..23265fa24 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -477,31 +477,32 @@ struct hplugin *hplugin_load(const char* filename) { return plugin; } -void hplugin_unload(struct hplugin* plugin) { - unsigned int i = plugin->idx; - - if( plugin->filename ) +void hplugin_unload(struct hplugin* plugin) +{ + if (plugin->filename) aFree(plugin->filename); - if( plugin->dll ) + if (plugin->dll) plugin_close(plugin->dll); /* TODO: for manual packet unload */ /* - Go through known packets and unlink any belonging to the plugin being removed */ - aFree(plugin); if (!HPM->off) { - int cursor = 0; - HPM->plugins[i] = NULL; - for(i = 0; i < HPM->plugin_count; i++) { - if( HPM->plugins[i] == NULL ) + int i, cursor; + for (cursor = 0; cursor < HPM->plugin_count; cursor++) { + if (HPM->plugins[cursor]->idx != plugin->idx) continue; - if( cursor != i ) - HPM->plugins[cursor] = HPM->plugins[i]; + HPM->plugins[cursor] = NULL; + break; + } + for(i = cursor + 1; i < HPM->plugin_count; i++) { + HPM->plugins[cursor] = HPM->plugins[i]; cursor++; } - if( !(HPM->plugin_count = cursor) ) { + if (!(HPM->plugin_count = cursor)) { aFree(HPM->plugins); HPM->plugins = NULL; } } + aFree(plugin); } /** @@ -560,8 +561,8 @@ void hplugins_config_read(void) { if ((plugin = HPM->load(filename))) { const char * (*func)(bool *fr); bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID); - if ((func = plugin_import(plugin->dll, "Hooked",const char * (*)(bool *))) - && (addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int)))) { + if ((func = plugin_import(plugin->dll, "Hooked",const char * (*)(bool *))) != NULL + && (addhook_sub = plugin_import(plugin->dll, "HPM_Plugin_AddHook",bool (*)(enum HPluginHookType, const char *, void *, unsigned int))) != NULL) { const char *failed = func(&HPM->force_return); if (failed) { ShowError("HPM: failed to retrieve '%s' for '"CL_WHITE"%s"CL_RESET"'!\n", failed, plugin_name); @@ -580,8 +581,8 @@ void hplugins_config_read(void) { snprintf(filename, 60, "plugins/%s%s", libconfig->setting_get_string_elem(plist,i), DLL_EXT); HPM->load(filename); } - libconfig->destroy(&plugins_conf); } + libconfig->destroy(&plugins_conf); if( HPM->plugin_count ) ShowStatus("HPM: There are '"CL_WHITE"%d"CL_RESET"' plugins loaded, type '"CL_WHITE"plugins"CL_RESET"' to list them\n", HPM->plugin_count); |