1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

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.
This commit is contained in:
Sergei Golubchik
2017-08-13 01:08:30 +02:00
parent d924e0b993
commit 399e14f066
3 changed files with 31 additions and 8 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -643,17 +643,21 @@ error:
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();
}