summaryrefslogtreecommitdiff
path: root/sql/sp_head.cc
diff options
context:
space:
mode:
authorunknown <petr@mysql.com>2005-08-25 15:34:14 +0400
committerunknown <petr@mysql.com>2005-08-25 15:34:14 +0400
commitd29df5645bf0cdac2ff08a7da305e62edcd79604 (patch)
tree8fae7ec65a099365bef1673b8fe3f482e29eb39d /sql/sp_head.cc
parent141a36c31b9b9732a479f5b40a2ba35781418ad6 (diff)
downloadmariadb-git-d29df5645bf0cdac2ff08a7da305e62edcd79604.tar.gz
Fix Bug#11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO query"
mysql-test/r/sp.result: update result mysql-test/t/sp.test: Add test for Bug #11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO query" sql/item.cc: we should call destructors for Items before reuse sql/item.h: Add new method and constructor for Item_string. sql/sp_head.cc: String allocation should be done on the system heap for now.
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r--sql/sp_head.cc23
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;
}