mirror of
https://github.com/MariaDB/server.git
synced 2025-08-15 23:11:33 +02:00

On handling SP statement `FOR IN lower_bound..func() DO` the instruction sp_instr_set is allocated on sp_head's memory root, whereas an instance of the class Item_func_sp pointed by the data member sp_instr_set::sp_result_field is allocated on runtime memory root. In result, on finishing the first execution of a stored routine the memory allocated for the instance of the class Item_func_sp is released whereas the pointer sp_instr_set::sp_result_field still references the deleted memory. Next time the same stored routine is run dereferencing deallocated memory results in abnormal server termination. To fix the issue, allocate an instance of the class Item_func_sp on sp_head memory root. Do this allocation only once, meaning the Item_func_sp::cleanup doesn't do deletion an instance of the class Item_func_sp and nullifying the data member sp_instr_set::sp_result_field.
100 lines
2.3 KiB
Text
100 lines
2.3 KiB
Text
#
|
|
# MDEV-6610 Assertion `thd->is_error() || thd->killed' failed in mysql_execute_command on executing an SP with repeated CREATE TABLE .. SELECT
|
|
#
|
|
CREATE TABLE t1 (i INT);
|
|
SET @a = 2;
|
|
|
|
CREATE TABLE IF NOT EXISTS t2 (i INT) ENGINE = MyISAM
|
|
AS SELECT * FROM t1;
|
|
CREATE TABLE IF NOT EXISTS t2 (i INT) ENGINE = MyISAM
|
|
AS SELECT * FROM t1;
|
|
DROP TABLE t2;
|
|
|
|
--delimiter |
|
|
CREATE PROCEDURE sp()
|
|
BEGIN
|
|
REPEAT
|
|
CREATE TABLE IF NOT EXISTS t2 (i INT) ENGINE = MyISAM
|
|
AS SELECT * FROM t1;
|
|
SET @a = @a - 1;
|
|
UNTIL @a = 0
|
|
END REPEAT ;
|
|
END |
|
|
--delimiter ;
|
|
|
|
CALL sp();
|
|
|
|
DROP PROCEDURE sp;
|
|
DROP TABLE t1, t2;
|
|
|
|
--echo #
|
|
--echo # MDEV-36979 Same alias name with different case on same table is not working in functions
|
|
--echo #
|
|
create table t1 ( id int primary key auto_increment, name varchar(10));
|
|
insert into t1 (name) values ('wrbyviwb');
|
|
insert into t1 (name) values ('wrbyrwb1');
|
|
insert into t1 (name) values ('wrbrwb3');
|
|
select cnt.name from t1 cnt join ( select CMT.id from t1 CMT where CMT.id=1) t2 on t2.id=cnt.id;
|
|
delimiter //;
|
|
create function t1test(val int) returns varchar(400) charset utf8
|
|
begin
|
|
declare output varchar(400) default '';
|
|
set output = (select cnt.name from t1 cnt join ( select CMT.id from t1 CMT where CMT.id=val) t2 on t2.id=cnt.id);
|
|
return output;
|
|
end//
|
|
delimiter ;//
|
|
select t1test(1);
|
|
drop function t1test;
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-36814 MariaDB 10.11.9 Signal 11 crash on second Stored Procedure call
|
|
--echo #
|
|
set names utf8;
|
|
create table t1 (a varchar(1000));
|
|
--delimiter //
|
|
create procedure p1(in p_a varchar(1000)) insert into t1 values (p_a);//
|
|
create procedure p2(in s varchar(10))
|
|
begin
|
|
if s = '1' then set @startDate = now(); end if;
|
|
if s = '2' then set @startDate = '2025-05-23'; end if;
|
|
call p1(concat(s, @startDate, ' and '));
|
|
end;//
|
|
--delimiter ;
|
|
call p2('1');
|
|
call p2('2');
|
|
drop table t1;
|
|
drop procedure p1;
|
|
drop procedure p2;
|
|
|
|
--echo #
|
|
--echo # MDEV-26115: Crash when calling stored function in FOR loop argument
|
|
--echo #
|
|
--delimiter $
|
|
CREATE OR REPLACE FUNCTION cnt()
|
|
RETURNS INTEGER NO SQL
|
|
BEGIN
|
|
RETURN 3;
|
|
END;
|
|
$
|
|
|
|
CREATE OR REPLACE PROCEDURE p1()
|
|
NO SQL
|
|
BEGIN
|
|
DECLARE i INTEGER;
|
|
FOR i IN 1..cnt() DO
|
|
SELECT 1;
|
|
END FOR;
|
|
END;
|
|
$
|
|
|
|
--delimiter ;
|
|
|
|
CALL p1();
|
|
CALL p1();
|
|
|
|
--echo # Clean up
|
|
DROP FUNCTION cnt;
|
|
DROP PROCEDURE p1;
|
|
|
|
--echo # End of 10.11 tests
|