=== modified file 'ChangeLog' --- ChangeLog 2012-09-17 20:17:05 +0000 +++ ChangeLog 2012-11-23 12:31:28 +0000 @@ -1,3 +1,11 @@ +5.2.3 + + Bugs fixed: + * Memory leak in 5.2.2(w) ODBC driver causes Prepared_stmt_count to grow + (Bug# 67340/14812778) + +---- + 5.2.2 (10-Sep-2012) Bugs fixed: === modified file 'driver/my_prepared_stmt.c' --- driver/my_prepared_stmt.c 2012-09-06 21:59:16 +0000 +++ driver/my_prepared_stmt.c 2012-11-23 12:21:55 +0000 @@ -241,9 +241,11 @@ { if (stmt->ssps != NULL) { + my_bool close_result; free_result_bind(stmt); - assert(mysql_stmt_close(stmt->ssps) == '\0'); + close_result= mysql_stmt_close(stmt->ssps); + assert(close_result == '\0'); stmt->ssps= NULL; } } === modified file 'test/my_prepare.c' --- test/my_prepare.c 2012-08-09 11:14:17 +0000 +++ test/my_prepare.c 2012-11-23 12:31:00 +0000 @@ -1075,6 +1075,56 @@ } +/** + Bug #67340: Memory leak in 5.2.2(w) ODBC driver + causes Prepared_stmt_count to grow +*/ +DECLARE_TEST(t_bug67340) +{ + SQLCHAR *param= (SQLCHAR *)"1"; + SQLCHAR data[255]= "abcdefg"; + SQLLEN paramlen= 7; + int i, stmt_count= 0; + int res= OK; + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug67340"); + ok_sql(hstmt, "CREATE TABLE t_bug67340(id INT AUTO_INCREMENT PRIMARY KEY,"\ + "vc VARCHAR(32))"); + + /* get the initial numnber of Prepared_stmt_count */ + ok_sql(hstmt, "SHOW STATUS LIKE 'Prepared_stmt_count'"); + ok_stmt(hstmt, SQLFetch(hstmt)); + stmt_count= my_fetch_int(hstmt, 2); + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + for(i=0; i < 100; i++) + { + ok_stmt(hstmt, SQLPrepare(hstmt, "INSERT INTO t_bug67340(id, vc) "\ + "VALUES (NULL, ?)", SQL_NTS)); + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, + SQL_CHAR, 0, 0, data, sizeof(data), + ¶mlen)); + ok_stmt(hstmt, SQLExecute(hstmt)); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND)); + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS)); + } + + /* get the new numnber of Prepared_stmt_count */ + ok_sql(hstmt, "SHOW STATUS LIKE 'Prepared_stmt_count'"); + ok_stmt(hstmt, SQLFetch(hstmt)); + + /* check how much Prepared_stmt_count has increased */ + if(my_fetch_int(hstmt, 2) - stmt_count > 1) + res= FAIL; + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + ok_sql(hstmt, "DROP TABLE t_bug67340"); + return res; +} + + BEGIN_TESTS ADD_TEST(t_prep_basic) ADD_TEST(t_prep_buffer_length) @@ -1090,6 +1140,7 @@ ADD_TEST(tmysql_bindparam) ADD_TEST(t_acc_update) ADD_TEST(t_bug29871) + ADD_TEST(t_bug67340) END_TESTS