Skip to content

Commit 62fd45f

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fixed bug #77599 (Unbuffered queries; native prepared statements memory leak)
2 parents 26e2696 + b6e58dc commit 62fd45f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
797797
MYSQLND_PACKET_ROW * row_packet;
798798
MYSQLND_CONN_DATA * conn = result->conn;
799799
const MYSQLND_RES_METADATA * const meta = result->meta;
800+
void *checkpoint;
800801

801802
DBG_ENTER("mysqlnd_stmt_fetch_row_unbuffered");
802803

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

823+
checkpoint = result->memory_pool->checkpoint;
824+
mysqlnd_mempool_save_state(result->memory_pool);
825+
822826
/*
823827
If we skip rows (stmt == NULL || stmt->result_bind == NULL) we have to
824828
result->unbuf->m.free_last_data() before it. The function returns always true.
@@ -841,6 +845,8 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
841845
conn->options->int_and_float_native,
842846
conn->stats))
843847
{
848+
mysqlnd_mempool_restore_state(result->memory_pool);
849+
result->memory_pool->checkpoint = checkpoint;
844850
DBG_RETURN(FAIL);
845851
}
846852

@@ -900,6 +906,9 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
900906
}
901907
}
902908

909+
mysqlnd_mempool_restore_state(result->memory_pool);
910+
result->memory_pool->checkpoint = checkpoint;
911+
903912
DBG_INF_FMT("ret=%s fetched_anything=%u", ret == PASS? "PASS":"FAIL", *fetched_anything);
904913
DBG_RETURN(ret);
905914
}

0 commit comments

Comments
 (0)