From 666607f9bc57eefb8fe20b44c19caab13077080d Mon Sep 17 00:00:00 2001 From: kjarir Date: Fri, 3 Apr 2026 11:09:06 +0530 Subject: [PATCH] MDEV-36345: Fix memleak in plugin_add() on hash insert failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In plugin_add(), init_alloc_root() was called unconditionally after plugin_insert_or_reuse(), even when my_hash_insert() failed and the plugin state was set to PLUGIN_IS_FREED. This caused a memory leak because the newly initialized mem_root was never freed — plugin_del() only frees mem_root for plugins that go through the normal deletion path, not ones immediately marked as PLUGIN_IS_FREED due to hash insertion failure. Fix: Guard init_alloc_root() with else so it is only called when my_hash_insert() succeeds. --- sql/sql_plugin.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 4b9218cbdc0ca..c1f816299718a 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1206,8 +1206,9 @@ static enum install_status plugin_add(MEM_ROOT *tmp_root, bool if_not_exists, goto err; if (my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr)) tmp_plugin_ptr->state= PLUGIN_IS_FREED; - init_alloc_root(key_memory_plugin_int_mem_root, &tmp_plugin_ptr->mem_root, - 4096, 4096, MYF(0)); + else + init_alloc_root(key_memory_plugin_int_mem_root, &tmp_plugin_ptr->mem_root, + 4096, 4096, MYF(0)); if (name->str) DBUG_RETURN(INSTALL_GOOD); // all done