Skip to content

Commit e038a7f

Browse files
author
holzboote@googlemail.com
committed
Fix for CONC-97 and CONC-98:
- Check if the connection is valid before resetting statement - Fix windows compile error (mingw)
1 parent 72b1570 commit e038a7f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

libmariadb/my_stmt.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags)
16621662
if (flags & MADB_RESET_SERVER)
16631663
{
16641664
/* reset statement on server side */
1665-
if (stmt->mysql->status == MYSQL_STATUS_READY)
1665+
if (stmt->mysql && stmt->mysql->status == MYSQL_STATUS_READY)
16661666
{
16671667
unsigned char cmd_buf[STMT_ID_LENGTH];
16681668
int4store(cmd_buf, stmt->stmt_id);
@@ -1698,6 +1698,14 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt)
16981698

16991699
DBUG_ENTER("mysql_stmt_reset");
17001700

1701+
if (!mysql)
1702+
{
1703+
/* connection could be invalid, e.g. after mysql_stmt_close or failed reconnect
1704+
attempt (see bug CONC-97) */
1705+
SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0);
1706+
DBUG_RETURN(1);
1707+
}
1708+
17011709
if (stmt->state >= MYSQL_STMT_USER_FETCHING &&
17021710
stmt->fetch_row_func == stmt_unbuffered_fetch)
17031711
flags|= MADB_RESET_BUFFER;

libmariadb/mysql_async.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*/
4242
#define WIN_SET_NONBLOCKING(mysql) { \
4343
my_bool old_mode; \
44-
if ((mysql)->net.vio) vio_blocking((mysql)->net.vio, FALSE, &old_mode); \
44+
if ((mysql)->net.vio) vio_blocking((mysql)->net.vio, FALSE); \
4545
}
4646
#else
4747
#define WIN_SET_NONBLOCKING(mysql)

unittest/libmariadb/ps.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525

2626
/* Utility function to verify the field members */
2727

28+
static int test_conc97(MYSQL *mysql)
29+
{
30+
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
31+
int rc;
32+
33+
mysql_close(mysql);
34+
35+
rc= mysql_stmt_reset(stmt);
36+
FAIL_IF(!rc, "Error expected while resetting stmt");
37+
38+
rc= mysql_stmt_close(stmt);
39+
check_stmt_rc(rc, stmt);
40+
41+
mysql= mysql_init(NULL);
42+
43+
return OK;
44+
}
45+
2846
static int test_conc83(MYSQL *mysql)
2947
{
3048
MYSQL_STMT *stmt;
@@ -4844,6 +4862,7 @@ int test_notrunc(MYSQL *mysql)
48444862
}
48454863

48464864
struct my_tests_st my_tests[] = {
4865+
{"test_conc97", test_conc97, TEST_CONNECTION_NEW, 0, NULL, NULL},
48474866
{"test_conc83", test_conc83, TEST_CONNECTION_NEW, 0, NULL, NULL},
48484867
{"test_conc60", test_conc60, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
48494868
{"test_notrunc", test_notrunc, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},

0 commit comments

Comments
 (0)