Skip to content

Commit ff5349b

Browse files
author
unknown
committed
MDEV-6985: MariaDB crashes on stored procedure call
Item_ident fixed to allow double cleanup().
1 parent 357cb12 commit ff5349b

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

mysql-test/r/sp-innodb.result

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
drop table if exists t1,t2;
2+
drop procedure if exists p1;
3+
#
4+
#MDEV-6985: MariaDB crashes on stored procedure call
5+
#
6+
CREATE TABLE `t1` (
7+
`ID` int(11) NOT NULL,
8+
PRIMARY KEY (`ID`)
9+
) ENGINE=InnoDB;
10+
CREATE TABLE `t2` (
11+
`ID` int(11) NOT NULL,
12+
`DATE` datetime DEFAULT NULL,
13+
PRIMARY KEY (`ID`)
14+
) ENGINE=InnoDB;
15+
CREATE PROCEDURE `p1`()
16+
BEGIN
17+
DECLARE _mySelect CURSOR FOR
18+
SELECT DISTINCT t1.ID
19+
FROM t1
20+
LEFT JOIN t2 AS t2 ON
21+
t2.ID = t1.ID
22+
AND t2.DATE = (
23+
SELECT MAX(T3.DATE) FROM t2 AS T3 WHERE T3.ID = t2.ID AND T3.DATE<=NOW()
24+
)
25+
WHERE t1.ID = 1;
26+
OPEN _mySelect;
27+
CLOSE _mySelect;
28+
END ;;
29+
CALL p1();
30+
CALL p1();
31+
drop procedure p1;
32+
drop table t1,t2;

mysql-test/t/sp-innodb.test

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
--source include/have_innodb.inc
3+
4+
--disable_warnings
5+
drop table if exists t1,t2;
6+
drop procedure if exists p1;
7+
--enable_warnings
8+
9+
--echo #
10+
--echo #MDEV-6985: MariaDB crashes on stored procedure call
11+
--echo #
12+
CREATE TABLE `t1` (
13+
`ID` int(11) NOT NULL,
14+
PRIMARY KEY (`ID`)
15+
) ENGINE=InnoDB;
16+
17+
CREATE TABLE `t2` (
18+
`ID` int(11) NOT NULL,
19+
`DATE` datetime DEFAULT NULL,
20+
PRIMARY KEY (`ID`)
21+
) ENGINE=InnoDB;
22+
23+
--delimiter ;;
24+
25+
CREATE PROCEDURE `p1`()
26+
BEGIN
27+
DECLARE _mySelect CURSOR FOR
28+
SELECT DISTINCT t1.ID
29+
FROM t1
30+
LEFT JOIN t2 AS t2 ON
31+
t2.ID = t1.ID
32+
AND t2.DATE = (
33+
SELECT MAX(T3.DATE) FROM t2 AS T3 WHERE T3.ID = t2.ID AND T3.DATE<=NOW()
34+
)
35+
WHERE t1.ID = 1;
36+
OPEN _mySelect;
37+
CLOSE _mySelect;
38+
END ;;
39+
--delimiter ;
40+
41+
CALL p1();
42+
CALL p1();
43+
44+
drop procedure p1;
45+
drop table t1,t2;

sql/item.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,12 +862,20 @@ void Item_ident::cleanup()
862862
field_name ? field_name : "(null)",
863863
orig_field_name ? orig_field_name : "(null)"));
864864
#endif
865+
bool was_fixed= fixed;
865866
Item::cleanup();
866867
db_name= orig_db_name;
867868
table_name= orig_table_name;
868869
field_name= orig_field_name;
869870
/* Store if this Item was depended */
870-
can_be_depended= test(depended_from);
871+
if (was_fixed)
872+
{
873+
/*
874+
We can trust that depended_from set correctly only if this item
875+
was fixed
876+
*/
877+
can_be_depended= test(depended_from);
878+
}
871879
DBUG_VOID_RETURN;
872880
}
873881

0 commit comments

Comments
 (0)