diff --git a/mysql-test/suite/rpl/r/semisync_memleak_4066.result b/mysql-test/suite/rpl/r/semisync_memleak_4066.result new file mode 100644 index 00000000000..c0dd9f0c993 --- /dev/null +++ b/mysql-test/suite/rpl/r/semisync_memleak_4066.result @@ -0,0 +1,6 @@ +include/master-slave.inc +[connection master] +INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; +CREATE TEMPORARY TABLE tmp (i INT); +include/rpl_end.inc +uninstall plugin rpl_semi_sync_master; diff --git a/mysql-test/suite/rpl/t/semisync_memleak_4066.test b/mysql-test/suite/rpl/t/semisync_memleak_4066.test new file mode 100644 index 00000000000..687af883936 --- /dev/null +++ b/mysql-test/suite/rpl/t/semisync_memleak_4066.test @@ -0,0 +1,19 @@ +# +# MDEV-4066 semisync_master + temporary tables causes memory leaks +# +source include/have_semisync_plugin.inc; +source include/have_binlog_format_row.inc; +source include/master-slave.inc; + +connection master; + +--replace_result .dll .so +eval INSTALL PLUGIN rpl_semi_sync_master SONAME '$SEMISYNC_MASTER_SO'; + +--connect (con1,localhost,root,,) +CREATE TEMPORARY TABLE tmp (i INT); +--disconnect con1 + +source include/rpl_end.inc; +uninstall plugin rpl_semi_sync_master; + diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 18b59a8c2fc..33dc4218e95 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1383,11 +1383,12 @@ void THD::cleanup(void) #error xid_state in the cache should be replaced by the allocated value } #endif - { - transaction.xid_state.xa_state= XA_NOTR; - trans_rollback(this); - xid_cache_delete(&transaction.xid_state); - } + + close_temporary_tables(this); + + transaction.xid_state.xa_state= XA_NOTR; + trans_rollback(this); + xid_cache_delete(&transaction.xid_state); locked_tables_list.unlock_locked_tables(this); mysql_ha_cleanup(this); @@ -1421,7 +1422,6 @@ void THD::cleanup(void) delete_dynamic(&user_var_events); my_hash_free(&user_vars); - close_temporary_tables(this); sp_cache_clear(&sp_proc_cache); sp_cache_clear(&sp_func_cache);