Skip to content

Commit 1a306cc

Browse files
committed
Fixed bug #77308 (Unbuffered queries memory leak)
1 parent 5c3b17c commit 1a306cc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ PHP NEWS
3434
(64796c6e69 at gmail dot com)
3535

3636
- MySQLnd:
37+
. Fixed bug #77308 (Unbuffered queries memory leak). (Dmitry)
3738
. Fixed bug #75684 (In mysqlnd_ext_plugin.h the plugin methods family has
3839
no external visibility). (Anatol)
3940

ext/mysqlnd/mysqlnd_result.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row_c)(MYSQLND_RES * result, voi
651651
MYSQLND_PACKET_ROW *row_packet = result->unbuf->row_packet;
652652
MYSQLND_RES_METADATA * const meta = result->meta;
653653
MYSQLND_CONN_DATA * const conn = result->conn;
654+
void *checkpoint;
654655

655656
DBG_ENTER("mysqlnd_result_unbuffered::fetch_row_c");
656657

@@ -670,6 +671,9 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row_c)(MYSQLND_RES * result, voi
670671
/* Let the row packet fill our buffer and skip additional mnd_malloc + memcpy */
671672
row_packet->skip_extraction = FALSE;
672673

674+
checkpoint = result->memory_pool->checkpoint;
675+
mysqlnd_mempool_save_state(result->memory_pool);
676+
673677
/*
674678
If we skip rows (row == NULL) we have to
675679
result->m.unbuffered_free_last_data() before it. The function returns always true.
@@ -694,6 +698,8 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row_c)(MYSQLND_RES * result, voi
694698
conn->options->int_and_float_native,
695699
conn->stats);
696700
if (PASS != rc) {
701+
mysqlnd_mempool_restore_state(result->memory_pool);
702+
result->memory_pool->checkpoint = checkpoint;
697703
DBG_RETURN(FAIL);
698704
}
699705
{
@@ -757,6 +763,9 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row_c)(MYSQLND_RES * result, voi
757763
result->unbuf->m.free_last_data(result->unbuf, conn->stats);
758764
}
759765

766+
mysqlnd_mempool_restore_state(result->memory_pool);
767+
result->memory_pool->checkpoint = checkpoint;
768+
760769
DBG_INF_FMT("ret=%s fetched=%u", ret == PASS? "PASS":"FAIL", *fetched_anything);
761770
DBG_RETURN(PASS);
762771
}

0 commit comments

Comments
 (0)