Commit 075e0220 authored by unknown's avatar unknown

Bug #33796 Memory leak for prepared statements in embedded server.

Field data for a query was stored to the stmt->alloc that is emptied
with mysql_stmt_close statement only. That means a lot of memory can
be occupied without a reason if used doesn't call mysql_stmt_close often.


libmysql/libmysql.c:
  Bug #33796 Memory leak for prepared statements in embedded server.
  
  Clean up result->alloc even if there's no 'data' created
libmysqld/lib_sql.cc:
  Bug #33796 Memory leak for prepared statements in embedded server.
  
  alloc 'fields' in the 'result.alloc' as the 'mem_root' is only cleaned with
  mysql_stmt_close'
parent 299f71fb
...@@ -4522,14 +4522,11 @@ my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt) ...@@ -4522,14 +4522,11 @@ my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt)
{ {
MYSQL *mysql= stmt->mysql; MYSQL *mysql= stmt->mysql;
if (result->data)
{
/* Result buffered */ /* Result buffered */
free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); free_root(&result->alloc, MYF(MY_KEEP_PREALLOC));
result->data= NULL; result->data= NULL;
result->rows= 0; result->rows= 0;
stmt->data_cursor= NULL; stmt->data_cursor= NULL;
}
if (mysql && stmt->field_count && if (mysql && stmt->field_count &&
(int) stmt->state > (int) MYSQL_STMT_PREPARE_DONE) (int) stmt->state > (int) MYSQL_STMT_PREPARE_DONE)
......
...@@ -668,7 +668,7 @@ bool Protocol::send_fields(List<Item> *list, uint flag) ...@@ -668,7 +668,7 @@ bool Protocol::send_fields(List<Item> *list, uint flag)
DBUG_RETURN(0); DBUG_RETURN(0);
field_count= list->elements; field_count= list->elements;
field_alloc= thd->current_stmt ? &thd->current_stmt->mem_root : field_alloc= thd->current_stmt ? &thd->current_stmt->result.alloc :
&mysql->field_alloc; &mysql->field_alloc;
if (!(client_field= mysql->fields= if (!(client_field= mysql->fields=
(MYSQL_FIELD *)alloc_root(field_alloc, (MYSQL_FIELD *)alloc_root(field_alloc,
......
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