Commit 399e14f0 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-13435 Crash when selecting virtual columns generated using JSON functions

don't allocate memory on thd->mem_root in every fix_fields(),
do it once and reuse.
parent d924e0b9
......@@ -59,3 +59,12 @@ a b
Warnings:
Warning 1292 Incorrect datetime value: '1'
drop table t1;
create table t1 (
id int not null ,
js varchar(1000) not null,
t time AS (cast(json_value(json_extract(js,concat('$.singleDay."', dayname(curdate()),'"')),'$.start') as time)) virtual);
insert into t1(id,js) values (0, '{"default" : {"start": "00:00:00", "end":"23:59:50"}}');
select * from t1;
id js t
0 {"default" : {"start": "00:00:00", "end":"23:59:50"}} NULL
drop table t1;
......@@ -37,3 +37,14 @@ disconnect con1;
connection default;
select * from t1;
drop table t1;
#
# MDEV-13435 Crash when selecting virtual columns generated using JSON functions
#
create table t1 (
id int not null ,
js varchar(1000) not null,
t time AS (cast(json_value(json_extract(js,concat('$.singleDay."', dayname(curdate()),'"')),'$.start') as time)) virtual);
insert into t1(id,js) values (0, '{"default" : {"start": "00:00:00", "end":"23:59:50"}}');
select * from t1;
drop table t1;
......@@ -643,17 +643,21 @@ String *Item_func_json_unquote::val_str(String *str)
static int alloc_tmp_paths(THD *thd, uint n_paths,
json_path_with_flags **paths,String **tmp_paths)
json_path_with_flags **paths, String **tmp_paths)
{
if (n_paths > 0)
{
*paths= (json_path_with_flags *) alloc_root(thd->mem_root,
sizeof(json_path_with_flags) * n_paths);
*tmp_paths= (String *) alloc_root(thd->mem_root, sizeof(String) * n_paths);
if (*paths == 0 || *tmp_paths == 0)
return 1;
if (*tmp_paths == 0)
{
MEM_ROOT *root= thd->stmt_arena->mem_root;
*paths= (json_path_with_flags *) alloc_root(root,
sizeof(json_path_with_flags) * n_paths);
*tmp_paths= (String *) alloc_root(root, sizeof(String) * n_paths);
if (*paths == 0 || *tmp_paths == 0)
return 1;
bzero(*tmp_paths, sizeof(String) * n_paths);
bzero(*tmp_paths, sizeof(String) * n_paths);
}
return 0;
}
......@@ -687,7 +691,6 @@ void Item_json_str_multipath::cleanup()
{
for (uint i= get_n_paths(); i>0; i--)
tmp_paths[i-1].free();
tmp_paths= 0;
}
Item_str_func::cleanup();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment