diff options
author | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-09-28 17:04:02 +0530 |
---|---|---|
committer | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-09-28 17:04:02 +0530 |
commit | fdb3c64e429cdc6f2370b7f4eefc0fbaf72eac6d (patch) | |
tree | 360cc1de3fcd4e399342bbcd54f354197d90ec1f | |
parent | 15cd9195353282e54e109962d46e1900c9eff3d4 (diff) | |
download | mariadb-git-fdb3c64e429cdc6f2370b7f4eefc0fbaf72eac6d.tar.gz |
MDEV-22277 LeakSanitizer: detected memory leaks in mem_heap_create_block_func after attempt to create foreign key
- During online DDL, prepare phase error handler fails to remove
the memory allocated for newly created foreign keys.
-rw-r--r-- | mysql-test/suite/innodb/r/foreign_key.result | 11 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/foreign_key.test | 14 | ||||
-rw-r--r-- | storage/innobase/handler/handler0alter.cc | 6 | ||||
-rw-r--r-- | storage/xtradb/handler/handler0alter.cc | 6 |
4 files changed, 37 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index 378fe74e14b..e9fbc742379 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -233,3 +233,14 @@ Opened_table_definitions 2 Opened_tables 2 drop function foo; drop table t2, t1; +CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk)) ENGINE=InnoDB; +XA START 'xid'; +INSERT INTO t1 VALUES (1,2); +CREATE TABLE x AS SELECT * FROM t1; +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state +SET foreign_key_checks= OFF, innodb_lock_wait_timeout= 1; +ALTER TABLE t1 ADD FOREIGN KEY f (a) REFERENCES t1 (pk), LOCK=EXCLUSIVE; +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +XA END 'xid'; +XA ROLLBACK 'xid'; +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index b33fbf60675..3269aeed62b 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -285,6 +285,20 @@ show status like '%opened_tab%'; drop function foo; drop table t2, t1; +CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk)) ENGINE=InnoDB; +XA START 'xid'; +INSERT INTO t1 VALUES (1,2); +--error ER_XAER_RMFAIL +CREATE TABLE x AS SELECT * FROM t1; +--connect (con1,localhost,root,,test) +SET foreign_key_checks= OFF, innodb_lock_wait_timeout= 1; +--error ER_LOCK_WAIT_TIMEOUT +ALTER TABLE t1 ADD FOREIGN KEY f (a) REFERENCES t1 (pk), LOCK=EXCLUSIVE;# Cleanup +--disconnect con1 +--connection default +XA END 'xid'; +XA ROLLBACK 'xid'; +DROP TABLE t1; # # End of 10.1 tests # diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 682f09992a4..e2c7c4421c6 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -3376,6 +3376,12 @@ err_exit: trx_free_for_mysql(ctx->trx); trx_commit_for_mysql(ctx->prebuilt->trx); + for (uint i = 0; i < ctx->num_to_add_fk; i++) { + if (ctx->add_fk[i]) { + dict_foreign_free(ctx->add_fk[i]); + } + } + delete ctx; ha_alter_info->handler_ctx = NULL; diff --git a/storage/xtradb/handler/handler0alter.cc b/storage/xtradb/handler/handler0alter.cc index e1b2dcd2441..4126f6b60e0 100644 --- a/storage/xtradb/handler/handler0alter.cc +++ b/storage/xtradb/handler/handler0alter.cc @@ -3388,6 +3388,12 @@ err_exit: trx_free_for_mysql(ctx->trx); trx_commit_for_mysql(ctx->prebuilt->trx); + for (uint i = 0; i < ctx->num_to_add_fk; i++) { + if (ctx->add_fk[i]) { + dict_foreign_free(ctx->add_fk[i]); + } + } + delete ctx; ha_alter_info->handler_ctx = NULL; |