mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fix leak when the client disconnects with open prep statements
This commit is contained in:
@ -5299,14 +5299,11 @@ static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list)
|
|||||||
int4store(buff, stmt->stmt_id);
|
int4store(buff, stmt->stmt_id);
|
||||||
error= simple_command(stmt->mysql, COM_CLOSE_STMT, buff, 4, 1);
|
error= simple_command(stmt->mysql, COM_CLOSE_STMT, buff, 4, 1);
|
||||||
}
|
}
|
||||||
if (!error)
|
|
||||||
{
|
|
||||||
mysql_free_result(stmt->result);
|
mysql_free_result(stmt->result);
|
||||||
free_root(&stmt->mem_root, MYF(0));
|
free_root(&stmt->mem_root, MYF(0));
|
||||||
if (!skip_list)
|
if (!skip_list)
|
||||||
stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list);
|
stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list);
|
||||||
my_free((gptr) stmt, MYF(MY_WME));
|
my_free((gptr) stmt, MYF(MY_WME));
|
||||||
}
|
|
||||||
DBUG_RETURN(error);
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ int compare_prep_stmt(void *not_used, PREP_STMT *stmt, ulong *key)
|
|||||||
|
|
||||||
void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used)
|
void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used)
|
||||||
{
|
{
|
||||||
|
my_free((char *)stmt->param, MYF(MY_ALLOW_ZERO_PTR));
|
||||||
free_items(stmt->free_list);
|
free_items(stmt->free_list);
|
||||||
free_root(&stmt->mem_root, MYF(0));
|
free_root(&stmt->mem_root, MYF(0));
|
||||||
}
|
}
|
||||||
@ -683,12 +684,17 @@ static bool init_param_items(PREP_STMT *stmt)
|
|||||||
List<Item> ¶ms= stmt->thd->lex.param_list;
|
List<Item> ¶ms= stmt->thd->lex.param_list;
|
||||||
Item_param **to;
|
Item_param **to;
|
||||||
|
|
||||||
|
if (!stmt->param_count)
|
||||||
|
stmt->param= (Item_param **)0;
|
||||||
|
else
|
||||||
|
{
|
||||||
if (!(stmt->param= to= (Item_param **)
|
if (!(stmt->param= to= (Item_param **)
|
||||||
my_malloc(sizeof(Item_param *)*(stmt->param_count+1),
|
my_malloc(sizeof(Item_param *)*(stmt->param_count+1),
|
||||||
MYF(MY_WME))))
|
MYF(MY_WME))))
|
||||||
return 1;
|
return 1;
|
||||||
List_iterator<Item> param_iterator(params);
|
List_iterator<Item> param_iterator(params);
|
||||||
while ((*(to++)= (Item_param *)param_iterator++));
|
while ((*(to++)= (Item_param *)param_iterator++));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,9 +884,8 @@ void mysql_stmt_free(THD *thd, char *packet)
|
|||||||
send_error(thd); // Not seen by the client
|
send_error(thd); // Not seen by the client
|
||||||
DBUG_VOID_RETURN;
|
DBUG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
my_free((char *)stmt->param, MYF(MY_ALLOW_ZERO_PTR));
|
tree_delete(&thd->prepared_statements, (void*) &stmt_id, (void *)0);
|
||||||
tree_delete(&thd->prepared_statements, (void*) &stmt, (void *)0);
|
thd->last_prepared_stmt= (PREP_STMT *)0;
|
||||||
thd->last_prepared_stmt=0;
|
|
||||||
DBUG_VOID_RETURN;
|
DBUG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,6 +284,7 @@ static void my_print_result_metadata(MYSQL_RES *result)
|
|||||||
|
|
||||||
mysql_field_seek(result,0);
|
mysql_field_seek(result,0);
|
||||||
fputc('\n', stdout);
|
fputc('\n', stdout);
|
||||||
|
fputc('\n', stdout);
|
||||||
|
|
||||||
field_count = mysql_num_fields(result);
|
field_count = mysql_num_fields(result);
|
||||||
for(i=0; i< field_count; i++)
|
for(i=0; i< field_count; i++)
|
||||||
@ -702,6 +703,7 @@ static void test_tran_bdb()
|
|||||||
mytest(result);
|
mytest(result);
|
||||||
|
|
||||||
my_process_result_set(result);
|
my_process_result_set(result);
|
||||||
|
mysql_free_result(result);
|
||||||
|
|
||||||
/* test the results now, only one row should exists */
|
/* test the results now, only one row should exists */
|
||||||
rc = mysql_query(mysql,"SELECT * FROM my_demo_transaction");
|
rc = mysql_query(mysql,"SELECT * FROM my_demo_transaction");
|
||||||
@ -779,6 +781,7 @@ static void test_tran_innodb()
|
|||||||
mytest(result);
|
mytest(result);
|
||||||
|
|
||||||
my_process_result_set(result);
|
my_process_result_set(result);
|
||||||
|
mysql_free_result(result);
|
||||||
|
|
||||||
/* test the results now, only one row should exists */
|
/* test the results now, only one row should exists */
|
||||||
rc = mysql_query(mysql,"SELECT * FROM my_demo_transaction");
|
rc = mysql_query(mysql,"SELECT * FROM my_demo_transaction");
|
||||||
@ -930,6 +933,7 @@ static void test_prepare_field_result()
|
|||||||
param_count= mysql_num_fields(result);
|
param_count= mysql_num_fields(result);
|
||||||
fprintf(stdout,"\n\n total fields: `%d` (expected: `5`)", param_count);
|
fprintf(stdout,"\n\n total fields: `%d` (expected: `5`)", param_count);
|
||||||
myassert(param_count == 5);
|
myassert(param_count == 5);
|
||||||
|
mysql_free_result(result);
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1478,7 +1482,7 @@ static void test_select_direct()
|
|||||||
*********************************************************/
|
*********************************************************/
|
||||||
static void test_select_prepare()
|
static void test_select_prepare()
|
||||||
{
|
{
|
||||||
int rc, count;
|
int rc;
|
||||||
MYSQL_STMT *stmt;
|
MYSQL_STMT *stmt;
|
||||||
|
|
||||||
myheader("test_select_prepare");
|
myheader("test_select_prepare");
|
||||||
@ -1511,7 +1515,8 @@ static void test_select_prepare()
|
|||||||
rc = mysql_execute(stmt);
|
rc = mysql_execute(stmt);
|
||||||
mystmt(stmt,rc);
|
mystmt(stmt,rc);
|
||||||
|
|
||||||
count= my_process_stmt_result(stmt);
|
myassert(1 == my_process_stmt_result(stmt));
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
rc = mysql_query(mysql,"DROP TABLE test_select");
|
rc = mysql_query(mysql,"DROP TABLE test_select");
|
||||||
myquery(rc);
|
myquery(rc);
|
||||||
@ -1540,8 +1545,7 @@ static void test_select_prepare()
|
|||||||
rc = mysql_execute(stmt);
|
rc = mysql_execute(stmt);
|
||||||
mystmt(stmt,rc);
|
mystmt(stmt,rc);
|
||||||
|
|
||||||
my_process_stmt_result(stmt);
|
myassert(1 == my_process_stmt_result(stmt));
|
||||||
|
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1615,7 +1619,7 @@ static void test_select()
|
|||||||
rc = mysql_execute(stmt);
|
rc = mysql_execute(stmt);
|
||||||
mystmt(stmt, rc);
|
mystmt(stmt, rc);
|
||||||
|
|
||||||
myassert(my_process_stmt_result(stmt) != 0);
|
myassert(my_process_stmt_result(stmt) == 1);
|
||||||
|
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
}
|
}
|
||||||
@ -1817,6 +1821,7 @@ static void test_long_data()
|
|||||||
verify_col_data("test_long_data","col1","999");
|
verify_col_data("test_long_data","col1","999");
|
||||||
verify_col_data("test_long_data","col2","Michael 'Monty' Widenius");
|
verify_col_data("test_long_data","col2","Michael 'Monty' Widenius");
|
||||||
verify_col_data("test_long_data","col3","Venu");
|
verify_col_data("test_long_data","col3","Venu");
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3608,8 +3613,9 @@ static void test_stmt_close()
|
|||||||
fprintf(stdout,"\n mysql_close_stmt(1) returned: %d", rc);
|
fprintf(stdout,"\n mysql_close_stmt(1) returned: %d", rc);
|
||||||
myassert(rc == 0);
|
myassert(rc == 0);
|
||||||
|
|
||||||
mysql_close(lmysql); /* it should free all open stmts(stmt3, stmt2) */
|
mysql_close(lmysql); /* it should free all open stmts(stmt3, 2 and 1) */
|
||||||
|
|
||||||
|
#if NOT_VALID
|
||||||
rc= mysql_stmt_close(stmt3);
|
rc= mysql_stmt_close(stmt3);
|
||||||
fprintf(stdout,"\n mysql_close_stmt(3) returned: %d", rc);
|
fprintf(stdout,"\n mysql_close_stmt(3) returned: %d", rc);
|
||||||
myassert( rc == 1);
|
myassert( rc == 1);
|
||||||
@ -3617,6 +3623,7 @@ static void test_stmt_close()
|
|||||||
rc= mysql_stmt_close(stmt2);
|
rc= mysql_stmt_close(stmt2);
|
||||||
fprintf(stdout,"\n mysql_close_stmt(2) returned: %d", rc);
|
fprintf(stdout,"\n mysql_close_stmt(2) returned: %d", rc);
|
||||||
myassert( rc == 1);
|
myassert( rc == 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
count= 100;
|
count= 100;
|
||||||
bind[0].buffer=(char *)&count;
|
bind[0].buffer=(char *)&count;
|
||||||
@ -3625,6 +3632,7 @@ static void test_stmt_close()
|
|||||||
|
|
||||||
rc = mysql_bind_param(stmt_x, bind);
|
rc = mysql_bind_param(stmt_x, bind);
|
||||||
mystmt(stmt_x, rc);
|
mystmt(stmt_x, rc);
|
||||||
|
|
||||||
rc = mysql_execute(stmt_x);
|
rc = mysql_execute(stmt_x);
|
||||||
mystmt(stmt_x, rc);
|
mystmt(stmt_x, rc);
|
||||||
|
|
||||||
@ -3673,7 +3681,6 @@ static void test_set_variable()
|
|||||||
result= mysql_param_result(stmt);
|
result= mysql_param_result(stmt);
|
||||||
mytest_r(result);
|
mytest_r(result);
|
||||||
|
|
||||||
|
|
||||||
bind[0].buffer_type= MYSQL_TYPE_LONG;
|
bind[0].buffer_type= MYSQL_TYPE_LONG;
|
||||||
bind[0].buffer=(char *)&select_limit;
|
bind[0].buffer=(char *)&select_limit;
|
||||||
bind[0].is_null=0;
|
bind[0].is_null=0;
|
||||||
@ -3745,6 +3752,8 @@ static void test_insert_meta()
|
|||||||
result= mysql_param_result(stmt);
|
result= mysql_param_result(stmt);
|
||||||
mytest_r(result);
|
mytest_r(result);
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
strmov(query,"INSERT INTO test_prep_insert VALUES(?,'venu',?)");
|
strmov(query,"INSERT INTO test_prep_insert VALUES(?,'venu',?)");
|
||||||
stmt = mysql_prepare(mysql, query, strlen(query));
|
stmt = mysql_prepare(mysql, query, strlen(query));
|
||||||
mystmt_init(stmt);
|
mystmt_init(stmt);
|
||||||
@ -3807,6 +3816,8 @@ static void test_update_meta()
|
|||||||
result= mysql_param_result(stmt);
|
result= mysql_param_result(stmt);
|
||||||
mytest_r(result);
|
mytest_r(result);
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
strmov(query,"UPDATE test_prep_update SET col1=?, col2='venu' WHERE col3=?");
|
strmov(query,"UPDATE test_prep_update SET col1=?, col2='venu' WHERE col3=?");
|
||||||
stmt = mysql_prepare(mysql, query, strlen(query));
|
stmt = mysql_prepare(mysql, query, strlen(query));
|
||||||
mystmt_init(stmt);
|
mystmt_init(stmt);
|
||||||
@ -3901,7 +3912,7 @@ static void test_select_meta()
|
|||||||
|
|
||||||
field= mysql_fetch_field(result);
|
field= mysql_fetch_field(result);
|
||||||
mytest_r(field);
|
mytest_r(field);
|
||||||
n
|
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
}
|
}
|
||||||
@ -4023,7 +4034,6 @@ static void test_multi_stmt()
|
|||||||
bind[1].length = &length[1];
|
bind[1].length = &length[1];
|
||||||
bind[1].is_null= &is_null[0];
|
bind[1].is_null= &is_null[0];
|
||||||
|
|
||||||
|
|
||||||
rc = mysql_bind_param(stmt, bind);
|
rc = mysql_bind_param(stmt, bind);
|
||||||
mystmt(stmt, rc);
|
mystmt(stmt, rc);
|
||||||
|
|
||||||
@ -4626,7 +4636,6 @@ static void test_store_result2()
|
|||||||
|
|
||||||
rc = mysql_fetch(stmt);
|
rc = mysql_fetch(stmt);
|
||||||
myassert(rc == MYSQL_NO_DATA);
|
myassert(rc == MYSQL_NO_DATA);
|
||||||
|
|
||||||
mysql_stmt_close(stmt);
|
mysql_stmt_close(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5239,13 +5248,17 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
MY_INIT(argv[0]);
|
MY_INIT(argv[0]);
|
||||||
get_options(argc,argv);
|
get_options(argc,argv);
|
||||||
|
time_t start_time, end_time;
|
||||||
|
double total_time= 0;
|
||||||
|
|
||||||
client_connect(); /* connect to server */
|
client_connect(); /* connect to server */
|
||||||
|
|
||||||
for (iter_count=1; iter_count <= opt_count; iter_count++)
|
for (iter_count=1; iter_count <= opt_count; iter_count++)
|
||||||
{
|
{
|
||||||
/* Start of tests */
|
/* Start of tests */
|
||||||
test_count= 0;
|
test_count= 1;
|
||||||
|
|
||||||
|
start_time= time((time_t *)0);
|
||||||
|
|
||||||
test_fetch_null(); /* to fetch null data */
|
test_fetch_null(); /* to fetch null data */
|
||||||
test_fetch_date(); /* to fetch date,time and timestamp */
|
test_fetch_date(); /* to fetch date,time and timestamp */
|
||||||
@ -5319,14 +5332,20 @@ int main(int argc, char **argv)
|
|||||||
test_manual_sample(); /* sample in the manual */
|
test_manual_sample(); /* sample in the manual */
|
||||||
test_pure_coverage(); /* keep pure coverage happy */
|
test_pure_coverage(); /* keep pure coverage happy */
|
||||||
test_buffers(); /* misc buffer handling */
|
test_buffers(); /* misc buffer handling */
|
||||||
|
|
||||||
|
end_time= time((time_t *)0);
|
||||||
|
total_time+= difftime(end_time, start_time);
|
||||||
/* End of tests */
|
/* End of tests */
|
||||||
}
|
}
|
||||||
|
|
||||||
client_disconnect(); /* disconnect from server */
|
client_disconnect(); /* disconnect from server */
|
||||||
fprintf(stdout,"\n\nAll '%d' tests were successful (in '%d' iterations)",
|
fprintf(stdout,"\n\nAll '%d' tests were successful (in '%d' iterations)",
|
||||||
test_count-1, opt_count);
|
test_count-1, opt_count);
|
||||||
|
fprintf(stdout,"\n Total execution time: %g SECS", total_time);
|
||||||
|
if (opt_count > 1)
|
||||||
|
fprintf(stdout," (Avg: %g SECS)", total_time/opt_count);
|
||||||
|
|
||||||
fprintf(stdout,"\nSUCCESS !!!\n");
|
fprintf(stdout,"\n\nSUCCESS !!!\n");
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user