diff --git a/mysql-test/main/constraints.result b/mysql-test/main/constraints.result index 105ea7cf1f4..77a25f5ad46 100644 --- a/mysql-test/main/constraints.result +++ b/mysql-test/main/constraints.result @@ -235,3 +235,16 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop procedure sp; drop table t1; +# +# MDEV-33768: Memory leak found in the test main.constraints run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT +# This test case was added by reviewer's request. +# +PREPARE stmt FROM 'CREATE TABLE t1 (a INT)'; +EXECUTE stmt; +DROP TABLE t1; +EXECUTE stmt; +EXECUTE stmt; +ERROR 42S01: Table 't1' already exists +# Clean up +DROP TABLE t1; +DEALLOCATE PREPARE stmt; diff --git a/mysql-test/main/constraints.test b/mysql-test/main/constraints.test index 5c673f9be81..83f3394d6f6 100644 --- a/mysql-test/main/constraints.test +++ b/mysql-test/main/constraints.test @@ -189,3 +189,18 @@ call sp; show create table t1; drop procedure sp; drop table t1; + +--echo # +--echo # MDEV-33768: Memory leak found in the test main.constraints run with --ps-protocol against a server built with the option -DWITH_PROTECT_STATEMENT_MEMROOT +--echo # This test case was added by reviewer's request. +--echo # +PREPARE stmt FROM 'CREATE TABLE t1 (a INT)'; +EXECUTE stmt; +DROP TABLE t1; +EXECUTE stmt; +--error ER_TABLE_EXISTS_ERROR +EXECUTE stmt; + +--echo # Clean up +DROP TABLE t1; +DEALLOCATE PREPARE stmt; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 839438dfc30..dc1a7060643 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5861,7 +5861,8 @@ static bool make_unique_constraint_name(THD *thd, LEX_CSTRING *name, if (!check) // Found unique name { name->length= (size_t) (real_end - buff); - name->str= strmake_root(thd->stmt_arena->mem_root, buff, name->length); + name->str= thd->strmake(buff, name->length); + return (name->str == NULL); } }