diff options
author | petr@mysql.com <> | 2005-08-25 15:34:14 +0400 |
---|---|---|
committer | petr@mysql.com <> | 2005-08-25 15:34:14 +0400 |
commit | 8dfa469729d82ec9f08bdb1ac191cec6c841458e (patch) | |
tree | 8fae7ec65a099365bef1673b8fe3f482e29eb39d /sql/sp_head.cc | |
parent | 6c03c9252d1a39cf545f8043683b704c9d69b3b5 (diff) | |
download | mariadb-git-8dfa469729d82ec9f08bdb1ac191cec6c841458e.tar.gz |
Fix Bug#11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO query"
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r-- | sql/sp_head.cc | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc index f119ef1ec22..0a3521e8855 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -249,10 +249,25 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type, DBUG_PRINT("info",("default result: %*s", s->length(), s->c_ptr_quick())); CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) - Item_string(thd->strmake(s->ptr(), - s->length()), s->length(), - it->collation.collation), - use_callers_arena, &backup_current_arena); + Item_string(it->collation.collation), + use_callers_arena, &backup_current_arena); + /* + We have to use special constructor and allocate string + on system heap here. This is because usual Item_string + constructor would allocate memory in the callers arena. + This would lead to the memory leak in SP loops. + See Bug #11333 "Stored Procedure: Memory blow up on + repeated SELECT ... INTO query" for sample of such SP. + TODO: Usage of the system heap gives significant overhead, + however usual "reuse" mechanism does not work here, as + Item_string has no max size. That is, if we have a loop, which + has string variable with constantly increasing size, we would have + to allocate new pieces of memory again and again on each iteration. + In future we should probably reserve some area of memory for + not-very-large strings and reuse it. But for large strings + we would have to use system heap anyway. + */ + ((Item_string*) it)->set_str_with_copy(s->ptr(), s->length()); } break; } |