From 76b639453b1fb251739b50438393b0e8b4e0ef12 Mon Sep 17 00:00:00 2001 From: Martin Alderete Date: Fri, 16 Feb 2024 19:15:10 +0100 Subject: [PATCH] Unified behaviour when calling "plugin->deinit" for all PUBLIC plugin's type by passing a reference to then plugin rather than `nullptr`. Before calling "plugin->deinit", MySQL verifies if for the given plugin's type there is a special function that handles the deinit phase. This is achieved by verifiying the array "plugin_type_deinitialize" in `sql/sql_plugin.cc`. Currently, there are 3 special functions: "ha_finalize_handlerton" (MYSQL_STORAGE_PLUGIN), "finalize_schema_table" (MYSQL_INFORMATION_SCHEMA_PLUGIN) and "finalize_audit_plugin" (MYSQL_AUDIT_PLUGIN). If there is not a special fuinction then MySQL check if the plugin exposes a "deinit" function and executes it passing the "plugin" as argument. Otherwise, MySQL calls the "special function" passing the plugin as argument. Then the special function check if the plugin exposes a "deinit" function and calls it but it always pass `nullptr` as argument rather than the plugin. Because of that, plugin's deinit cannot use plugin's struct and need to add "maybe_unused" (or "__attribute__((unused))") to the signature. --- sql/handler.cc | 2 +- sql/sql_audit.cc | 2 +- sql/sql_show.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index d9ae333609e2..18d1b1d1db94 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -747,7 +747,7 @@ int ha_finalize_handlerton(st_plugin_int *plugin) { engine plugins. */ DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str)); - if (plugin->plugin->deinit(nullptr)) { + if (plugin->plugin->deinit(plugin)) { DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", plugin->name.str)); } diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 6c768d2d5dd6..681d316c3597 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -766,7 +766,7 @@ static bool calc_class_mask(THD *, plugin_ref plugin, void *arg) { int finalize_audit_plugin(st_plugin_int *plugin) { unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; - if (plugin->plugin->deinit && plugin->plugin->deinit(nullptr)) { + if (plugin->plugin->deinit && plugin->plugin->deinit(plugin)) { DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", plugin->name.str)); DBUG_EXECUTE("finalize_audit_plugin", return 1;); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index a7e281b14bed..9c6e2bc35953 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -5139,7 +5139,7 @@ int finalize_schema_table(st_plugin_int *plugin) { if (schema_table) { if (plugin->plugin->deinit) { DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str)); - if (plugin->plugin->deinit(nullptr)) { + if (plugin->plugin->deinit(plugin)) { DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", plugin->name.str)); }