=== modified file 'driver/catalog_no_i_s.c' --- driver/catalog_no_i_s.c 2013-08-05 06:13:11 +0000 +++ driver/catalog_no_i_s.c 2013-09-04 06:44:38 +0000 @@ -2141,6 +2141,7 @@ if (!row_count) { mysql_free_result(stmt->result); + stmt->result= NULL; goto empty_set; } === modified file 'driver/my_prepared_stmt.c' --- driver/my_prepared_stmt.c 2012-11-26 12:13:08 +0000 +++ driver/my_prepared_stmt.c 2013-09-04 06:44:38 +0000 @@ -1,5 +1,5 @@ /* - Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2012-2013, Oracle and/or its affiliates. All rights reserved. The MySQL Connector/ODBC is licensed under the terms of the GPLv2 , like most @@ -223,10 +223,17 @@ { if (stmt->result_bind != NULL) { + int i, field_cnt= field_count(stmt); + x_free(stmt->result_bind[0].is_null); x_free(stmt->result_bind[0].length); x_free(stmt->result_bind[0].error); - x_free(stmt->result_bind[0].buffer); + + /* buffer was allocated for each column */ + for (i= 0; i < field_cnt; i++) + { + x_free(stmt->result_bind[i].buffer); + } x_free(stmt->result_bind); stmt->result_bind= 0; @@ -438,11 +445,11 @@ IS_PS_OUT_PARAMS(stmt)); stmt->result_bind[i].buffer_type = p.type; - stmt->result_bind[i].buffer = p.buffer; - stmt->result_bind[i].buffer_length= (unsigned long)p.size; - stmt->result_bind[i].length = &len[i]; - stmt->result_bind[i].is_null = &is_null[i]; - stmt->result_bind[i].error = &err[i]; + stmt->result_bind[i].buffer = p.buffer; + stmt->result_bind[i].buffer_length= (unsigned long)p.size; + stmt->result_bind[i].length = &len[i]; + stmt->result_bind[i].is_null = &is_null[i]; + stmt->result_bind[i].error = &err[i]; stmt->result_bind[i].is_unsigned = (field->flags & UNSIGNED_FLAG)? 1: 0; stmt->array[i]= p.buffer; === modified file 'driver/my_stmt.c' --- driver/my_stmt.c 2012-09-03 22:39:51 +0000 +++ driver/my_stmt.c 2013-09-04 06:44:38 +0000 @@ -44,7 +44,16 @@ if (ssps_used(stmt)) { /* Basically at this point we are supposed to get result already */ - return stmt->result ? TRUE : mysql_stmt_result_metadata(stmt->ssps) != NULL; + MYSQL_RES *temp_res= NULL; + + if ((stmt->result != NULL) || + (temp_res= mysql_stmt_result_metadata(stmt->ssps)) != NULL) + { + /* mysql_free_result checks for NULL, so we can always call it */ + mysql_free_result(temp_res); + return TRUE; + } + return FALSE; } else { @@ -55,24 +64,18 @@ my_bool free_current_result(STMT *stmt) { + my_bool res= 0; if (returned_result(stmt)) { if (ssps_used(stmt)) - - { - my_bool res= mysql_stmt_free_result(stmt->ssps); - stmt->result= NULL; - - return res; - } - else - { - mysql_free_result(stmt->result); - stmt->result= NULL; - return '\0'; - } + { + res= mysql_stmt_free_result(stmt->ssps); + } + /* We need to always free stmt->result because SSPS keep metadata there */ + mysql_free_result(stmt->result); + stmt->result= NULL; } - return '\0'; + return res; } @@ -98,6 +101,9 @@ we need to use/store each resultset of multiple resultsets */ MYSQL_RES * get_result_metadata(STMT *stmt, BOOL force_use) { + /* just a precaution, mysql_free_result checks for NULL anywat */ + mysql_free_result(stmt->result); + if (ssps_used(stmt)) { stmt->result= mysql_stmt_result_metadata(stmt->ssps); @@ -399,6 +405,9 @@ stmt->param_count= mysql_stmt_param_count(stmt->ssps); + /* make sure we free the result from the previous time */ + mysql_free_result(stmt->result); + /* Getting result metadata */ if ((stmt->result= mysql_stmt_result_metadata(stmt->ssps))) {