Skip to content

Commit b6e58dc

Browse files
committed
Fixed bug #77599 (Unbuffered queries; native prepared statements memory leak)
1 parent 470f589 commit b6e58dc

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ PHP NEWS
1818
. Fixed bug #77514 (mb_ereg_replace() with trailing backslash adds null byte).
1919
(Nikita)
2020

21+
- MySQLnd:
22+
. Fixed bug #77599 (Unbuffered queries; native prepared statements memory
23+
leak). (Dmitry)
24+
2125
- OpenSSL:
2226
. Fixed bug #77390 (feof might hang on TLS streams in case of fragmented TLS
2327
records). (Abyl Valg, Jakub Zelenka)

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
851851
MYSQLND_PACKET_ROW * row_packet;
852852
MYSQLND_CONN_DATA * conn = result->conn;
853853
const MYSQLND_RES_METADATA * const meta = result->meta;
854+
void *checkpoint;
854855

855856
DBG_ENTER("mysqlnd_stmt_fetch_row_unbuffered");
856857

@@ -873,6 +874,9 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
873874
/* Let the row packet fill our buffer and skip additional malloc + memcpy */
874875
row_packet->skip_extraction = stmt && stmt->result_bind? FALSE:TRUE;
875876

877+
checkpoint = result->memory_pool->checkpoint;
878+
mysqlnd_mempool_save_state(result->memory_pool);
879+
876880
/*
877881
If we skip rows (stmt == NULL || stmt->result_bind == NULL) we have to
878882
result->unbuf->m.free_last_data() before it. The function returns always true.
@@ -895,6 +899,8 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
895899
conn->options->int_and_float_native,
896900
conn->stats))
897901
{
902+
mysqlnd_mempool_restore_state(result->memory_pool);
903+
result->memory_pool->checkpoint = checkpoint;
898904
DBG_RETURN(FAIL);
899905
}
900906

@@ -965,6 +971,9 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
965971
}
966972
}
967973

974+
mysqlnd_mempool_restore_state(result->memory_pool);
975+
result->memory_pool->checkpoint = checkpoint;
976+
968977
DBG_INF_FMT("ret=%s fetched_anything=%u", ret == PASS? "PASS":"FAIL", *fetched_anything);
969978
DBG_RETURN(ret);
970979
}

0 commit comments

Comments
 (0)