From 73b58ac4873eb98057cc1f57b8e6fde53aa9b29d Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 1 Aug 2024 13:07:12 +0700 Subject: [PATCH] MDEV-34649: Memory leaks on running DELETE statement in PS mode with positional parameters Re-design of a way for handling the DELETE statement introduced by the task MDEV-28883, added regression caused by missing reset of the data member current_select->first_cond_optimization on handling the DELETE statement that results in a memory leaks on second execution of the same DELETE statement in PS mode. To fix memory leaks, added set of the data member current_select->first_cond_optimization to the value false on finishing execution of DELETE statement. --- mysql-test/main/ps_mem_leaks.result | 14 ++++++++++++++ mysql-test/main/ps_mem_leaks.test | 18 ++++++++++++++++++ sql/sql_delete.cc | 1 + 3 files changed, 33 insertions(+) diff --git a/mysql-test/main/ps_mem_leaks.result b/mysql-test/main/ps_mem_leaks.result index ebbccb71c6b..b915329ff18 100644 --- a/mysql-test/main/ps_mem_leaks.result +++ b/mysql-test/main/ps_mem_leaks.result @@ -148,3 +148,17 @@ CALL p1(2); DROP TABLE t1; DROP PROCEDURE p1; # End of 10.11 tests +# +# MDEV-34649: Memory leaks on running DELETE statement in PS mode with positional parameters +# +CREATE TABLE t1 (a INT, b VARCHAR(30)) CHARSET=utf8mb4; +INSERT INTO t1 VALUES (1, 'one'), (0, NULL), (3, 'three'), (4, 'four'); +PREPARE stmt FROM 'DELETE FROM t1 WHERE b=?' ; +SET @arg00=NULL; +EXECUTE stmt USING @arg00; +SET @arg00='one'; +EXECUTE stmt USING @arg00; +# Clean up +DEALLOCATE PREPARE stmt; +DROP TABLE t1; +# End of 11.1 diff --git a/mysql-test/main/ps_mem_leaks.test b/mysql-test/main/ps_mem_leaks.test index 75381e13116..e824200d0fb 100644 --- a/mysql-test/main/ps_mem_leaks.test +++ b/mysql-test/main/ps_mem_leaks.test @@ -167,3 +167,21 @@ DROP TABLE t1; DROP PROCEDURE p1; --echo # End of 10.11 tests + +--echo # +--echo # MDEV-34649: Memory leaks on running DELETE statement in PS mode with positional parameters +--echo # +CREATE TABLE t1 (a INT, b VARCHAR(30)) CHARSET=utf8mb4; +INSERT INTO t1 VALUES (1, 'one'), (0, NULL), (3, 'three'), (4, 'four'); +PREPARE stmt FROM 'DELETE FROM t1 WHERE b=?' ; +SET @arg00=NULL; +EXECUTE stmt USING @arg00; +SET @arg00='one'; +# Without the patch, attempt to run the same prepared statement the second time +# would result in memory leaks +EXECUTE stmt USING @arg00; +--echo # Clean up +DEALLOCATE PREPARE stmt; +DROP TABLE t1; + +--echo # End of 11.1 diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index b7b3b79bbb6..b1fc89b2a28 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -912,6 +912,7 @@ cleanup: { thd->lex->current_select->save_leaf_tables(thd); thd->lex->current_select->leaf_tables_saved= true; + thd->lex->current_select->first_cond_optimization= false; } delete deltempfile;