Skip to content

Commit ecb9db4

Browse files
FooBarriorvuvova
authored andcommitted
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.
1 parent 0695f7d commit ecb9db4

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

mysql-test/main/alter_table_online_debug.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,22 @@ connection default;
12961296
select * from t;
12971297
a b c
12981298
drop table t;
1299+
#
1300+
# MDEV-30949 Direct leak in binlog_online_alter_end_trans
1301+
#
1302+
create table t (f longblob default null) engine=myisam;
1303+
insert into t values (null);
1304+
set debug_sync= "alter_table_copy_end signal copy wait_for goon";
1305+
set debug_sync= "alter_table_online_before_lock signal lock wait_for end";
1306+
alter table t force, algorithm=copy;
1307+
connection con1;
1308+
set debug_sync= "now wait_for copy";
1309+
insert into t select repeat('a',130000);
1310+
set debug_sync= "now signal goon wait_for lock";
1311+
insert into t select repeat('a',130000);
1312+
set debug_sync= "now signal end";
1313+
connection default;
1314+
drop table t;
12991315
set debug_sync= reset;
13001316
disconnect con1;
13011317
disconnect con2;

mysql-test/main/alter_table_online_debug.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,30 @@ dec $i;
14751475
let local_engine=aria;
14761476
}
14771477

1478+
--echo #
1479+
--echo # MDEV-30949 Direct leak in binlog_online_alter_end_trans
1480+
--echo #
1481+
create table t (f longblob default null) engine=myisam;
1482+
insert into t values (null);
1483+
1484+
set debug_sync= "alter_table_copy_end signal copy wait_for goon";
1485+
set debug_sync= "alter_table_online_before_lock signal lock wait_for end";
1486+
1487+
send alter table t force, algorithm=copy;
1488+
1489+
--connection con1
1490+
set debug_sync= "now wait_for copy";
1491+
insert into t select repeat('a',130000);
1492+
set debug_sync= "now signal goon wait_for lock";
1493+
insert into t select repeat('a',130000);
1494+
set debug_sync= "now signal end";
1495+
1496+
1497+
--connection default
1498+
--reap
1499+
drop table t;
1500+
1501+
14781502
set debug_sync= reset;
14791503
--disconnect con1
14801504
--disconnect con2

sql/log.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ class Cache_flip_event_log: public Event_log {
512512
private:
513513
void cleanup()
514514
{
515-
end_io_cache(&alt_buf);
515+
close_cached_file(&log_file);
516+
close_cached_file(&alt_buf);
516517
Event_log::cleanup();
517518
}
518519
};

0 commit comments

Comments
 (0)