From ecb9db4c3d1470d1e3c6d4c4b7e9e8080849e9ba Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Tue, 18 Apr 2023 00:52:46 +0300 Subject: [PATCH] MDEV-30949 Direct leak in binlog_online_alter_end_trans when committing a big transaction, online_alter_cache_log creates a cache file. It wasn't properly closed, which was spotted by a memory leak from my_register_filename. A temporary file also remained open. Binlog wasn't affected by this, since it features its own file management. A proper closing is calling close_cached_file. It deinits io_cache and closes the underlying file. After closing, the file is expected to be deleted automagically. --- .../main/alter_table_online_debug.result | 16 +++++++++++++ mysql-test/main/alter_table_online_debug.test | 24 +++++++++++++++++++ sql/log.h | 3 ++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/alter_table_online_debug.result b/mysql-test/main/alter_table_online_debug.result index ebd48fa508c..69dd07e9525 100644 --- a/mysql-test/main/alter_table_online_debug.result +++ b/mysql-test/main/alter_table_online_debug.result @@ -1296,6 +1296,22 @@ connection default; select * from t; a b c drop table t; +# +# MDEV-30949 Direct leak in binlog_online_alter_end_trans +# +create table t (f longblob default null) engine=myisam; +insert into t values (null); +set debug_sync= "alter_table_copy_end signal copy wait_for goon"; +set debug_sync= "alter_table_online_before_lock signal lock wait_for end"; +alter table t force, algorithm=copy; +connection con1; +set debug_sync= "now wait_for copy"; +insert into t select repeat('a',130000); +set debug_sync= "now signal goon wait_for lock"; +insert into t select repeat('a',130000); +set debug_sync= "now signal end"; +connection default; +drop table t; set debug_sync= reset; disconnect con1; disconnect con2; diff --git a/mysql-test/main/alter_table_online_debug.test b/mysql-test/main/alter_table_online_debug.test index 598153ccb68..43e69155407 100644 --- a/mysql-test/main/alter_table_online_debug.test +++ b/mysql-test/main/alter_table_online_debug.test @@ -1475,6 +1475,30 @@ dec $i; let local_engine=aria; } +--echo # +--echo # MDEV-30949 Direct leak in binlog_online_alter_end_trans +--echo # +create table t (f longblob default null) engine=myisam; +insert into t values (null); + +set debug_sync= "alter_table_copy_end signal copy wait_for goon"; +set debug_sync= "alter_table_online_before_lock signal lock wait_for end"; + +send alter table t force, algorithm=copy; + +--connection con1 +set debug_sync= "now wait_for copy"; +insert into t select repeat('a',130000); +set debug_sync= "now signal goon wait_for lock"; +insert into t select repeat('a',130000); +set debug_sync= "now signal end"; + + +--connection default +--reap +drop table t; + + set debug_sync= reset; --disconnect con1 --disconnect con2 diff --git a/sql/log.h b/sql/log.h index 3d5ffe68876..83e323cb6fb 100644 --- a/sql/log.h +++ b/sql/log.h @@ -512,7 +512,8 @@ public: private: void cleanup() { - end_io_cache(&alt_buf); + close_cached_file(&log_file); + close_cached_file(&alt_buf); Event_log::cleanup(); } };