diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index 636f573c..60f7e30b 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -1662,7 +1662,7 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) if (flags & MADB_RESET_SERVER) { /* reset statement on server side */ - if (stmt->mysql->status == MYSQL_STATUS_READY) + if (stmt->mysql && stmt->mysql->status == MYSQL_STATUS_READY) { unsigned char cmd_buf[STMT_ID_LENGTH]; int4store(cmd_buf, stmt->stmt_id); @@ -1698,6 +1698,14 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) DBUG_ENTER("mysql_stmt_reset"); + if (!mysql) + { + /* connection could be invalid, e.g. after mysql_stmt_close or failed reconnect + attempt (see bug CONC-97) */ + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + DBUG_RETURN(1); + } + if (stmt->state >= MYSQL_STMT_USER_FETCHING && stmt->fetch_row_func == stmt_unbuffered_fetch) flags|= MADB_RESET_BUFFER; diff --git a/libmariadb/mysql_async.c b/libmariadb/mysql_async.c index 1a3cf421..57c33aab 100644 --- a/libmariadb/mysql_async.c +++ b/libmariadb/mysql_async.c @@ -41,7 +41,7 @@ */ #define WIN_SET_NONBLOCKING(mysql) { \ my_bool old_mode; \ - if ((mysql)->net.vio) vio_blocking((mysql)->net.vio, FALSE, &old_mode); \ + if ((mysql)->net.vio) vio_blocking((mysql)->net.vio, FALSE); \ } #else #define WIN_SET_NONBLOCKING(mysql) diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index 1b2495dc..5f60ce84 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -25,6 +25,24 @@ with this program; if not, write to the Free Software Foundation, Inc., /* Utility function to verify the field members */ +static int test_conc97(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + mysql_close(mysql); + + rc= mysql_stmt_reset(stmt); + FAIL_IF(!rc, "Error expected while resetting stmt"); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + mysql= mysql_init(NULL); + + return OK; +} + static int test_conc83(MYSQL *mysql) { MYSQL_STMT *stmt; @@ -4844,6 +4862,7 @@ int test_notrunc(MYSQL *mysql) } struct my_tests_st my_tests[] = { + {"test_conc97", test_conc97, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_conc83", test_conc83, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_conc60", test_conc60, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_notrunc", test_notrunc, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},