Skip to content

Commit be02356

Browse files
committed
MDEV-14959: Fixed memory leak happened on re-parsing a view that substitutes a table
In case a table accessed by a PS/SP is dropped after the first execution of PS/SP and a view created with the same name as a table just dropped then the second execution of PS/SP leads to allocation of a memory on SP/PS memory root already marked as read only on first execution. For example, the following test case: CREATE TABLE t1 (a INT); PREPARE stmt FROM "INSERT INTO t1 VALUES (1)"; EXECUTE stmt; DROP TABLE t1; CREATE VIEW t1 S SELECT 1; --error ER_NON_INSERTABLE_TABLE EXECUTE stmt; # (*) DROP VIEW t1; will hit assert on running the statement 'EXECUTE stmt' marked with (*) when allocation of a memory be performed on parsing the view. Memory allocation is requested inside the function mysql_make_view when a view definition being parsed. In order to avoid an assertion failure, call of the function mysql_make_view() must be moved after invocation of the function check_and_update_table_version(). It will result in re-preparing the whole PS statement or current SP instruction that will free currently allocated items and reset read_only flag for the memory root.
1 parent 1d502a2 commit be02356

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sql/sql_base.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,17 +2018,17 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
20182018
goto err_lock;
20192019
}
20202020

2021-
/* Open view */
2022-
if (mysql_make_view(thd, share, table_list, false))
2023-
goto err_lock;
2024-
20252021
/*
20262022
This table is a view. Validate its metadata version: in particular,
20272023
that it was a view when the statement was prepared.
20282024
*/
20292025
if (check_and_update_table_version(thd, table_list, share))
20302026
goto err_lock;
20312027

2028+
/* Open view */
2029+
if (mysql_make_view(thd, share, table_list, false))
2030+
goto err_lock;
2031+
20322032
/* TODO: Don't free this */
20332033
tdc_release_share(share);
20342034

0 commit comments

Comments
 (0)