Skip to content

Commit 020017e

Browse files
committed
Fix for CONPY123: Free pending result sets when closing cursor
When using text protocol pending result sets weren't properly freed, so executing another command on the same connection resulted in an error "commands out of sync".
1 parent 30caad5 commit 020017e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

mariadb/mariadb_cursor.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,11 @@ static void MrdbCursor_clear_result(MrdbCursor *self)
403403
/* clear pending result sets */
404404
if (self->connection->mysql)
405405
{
406-
while (!mysql_next_result(self->connection->mysql));
406+
do {
407+
MYSQL_RES *res;
408+
if ((res= mysql_use_result(self->connection->mysql)))
409+
mysql_free_result(res);
410+
} while (!mysql_next_result(self->connection->mysql));
407411
}
408412
}
409413
/* CONPY-52: Avoid possible double free */
@@ -480,6 +484,7 @@ void ma_cursor_close(MrdbCursor *self)
480484
{
481485
if (!self->is_closed)
482486
{
487+
MrdbCursor_clear_result(self);
483488
if (!self->is_text && self->stmt)
484489
{
485490
/* Todo: check if all the cursor stuff is deleted (when using prepared

testing/test/integration/test_cursor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,18 @@ def test_conpy68(self):
10421042
self.assertEqual(row[0], json.dumps(content))
10431043
del cursor
10441044

1045+
def test_conpy123(self):
1046+
con= create_connection({"client_flag" : CLIENT.MULTI_STATEMENTS})
1047+
cursor1= con.cursor()
1048+
cursor1.execute("SELECT 1; SELECT 2")
1049+
cursor1.close()
1050+
cursor2= con.cursor()
1051+
cursor2.execute("SELECT 1")
1052+
row= cursor2.fetchone()
1053+
self.assertEqual(row[0], 1)
1054+
cursor2.close()
1055+
con.close()
1056+
10451057
def test_conpy103(self):
10461058
con= create_connection()
10471059
cursor= con.cursor()

0 commit comments

Comments
 (0)