Skip to content

Commit 73b58ac

Browse files
committed
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.
1 parent 7ead48a commit 73b58ac

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

mysql-test/main/ps_mem_leaks.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,17 @@ CALL p1(2);
148148
DROP TABLE t1;
149149
DROP PROCEDURE p1;
150150
# End of 10.11 tests
151+
#
152+
# MDEV-34649: Memory leaks on running DELETE statement in PS mode with positional parameters
153+
#
154+
CREATE TABLE t1 (a INT, b VARCHAR(30)) CHARSET=utf8mb4;
155+
INSERT INTO t1 VALUES (1, 'one'), (0, NULL), (3, 'three'), (4, 'four');
156+
PREPARE stmt FROM 'DELETE FROM t1 WHERE b=?' ;
157+
SET @arg00=NULL;
158+
EXECUTE stmt USING @arg00;
159+
SET @arg00='one';
160+
EXECUTE stmt USING @arg00;
161+
# Clean up
162+
DEALLOCATE PREPARE stmt;
163+
DROP TABLE t1;
164+
# End of 11.1

mysql-test/main/ps_mem_leaks.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,21 @@ DROP TABLE t1;
167167
DROP PROCEDURE p1;
168168

169169
--echo # End of 10.11 tests
170+
171+
--echo #
172+
--echo # MDEV-34649: Memory leaks on running DELETE statement in PS mode with positional parameters
173+
--echo #
174+
CREATE TABLE t1 (a INT, b VARCHAR(30)) CHARSET=utf8mb4;
175+
INSERT INTO t1 VALUES (1, 'one'), (0, NULL), (3, 'three'), (4, 'four');
176+
PREPARE stmt FROM 'DELETE FROM t1 WHERE b=?' ;
177+
SET @arg00=NULL;
178+
EXECUTE stmt USING @arg00;
179+
SET @arg00='one';
180+
# Without the patch, attempt to run the same prepared statement the second time
181+
# would result in memory leaks
182+
EXECUTE stmt USING @arg00;
183+
--echo # Clean up
184+
DEALLOCATE PREPARE stmt;
185+
DROP TABLE t1;
186+
187+
--echo # End of 11.1

sql/sql_delete.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd)
912912
{
913913
thd->lex->current_select->save_leaf_tables(thd);
914914
thd->lex->current_select->leaf_tables_saved= true;
915+
thd->lex->current_select->first_cond_optimization= false;
915916
}
916917

917918
delete deltempfile;

0 commit comments

Comments
 (0)