[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Tue, 29 Sep 2026 16:41:54 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141702@lists.php.net to get a copy of this message
Author: Kamil Tekiela (kamil-tekiela) Date: 2026-09-29T17:39:33+01:00 Commit: https://github.com/php/php-src/commit/3014659bef4a9198eae8bf02384db7ff8d9db903 Raw diff: https://github.com/php/php-src/commit/3014659bef4a9198eae8bf02384db7ff8d9db903.diff Merge branch 'PHP-8.4' into PHP-8.5 Changed paths: A ext/mysqli/tests/mysqli_stmt_close_killed_connection.phpt M NEWS M ext/mysqli/mysqli.c M ext/mysqlnd/mysqlnd_ps.c Diff: diff --git a/NEWS b/NEWS index aaf9bb4574e8..084846690449 100644 --- a/NEWS +++ b/NEWS @@ -72,6 +72,8 @@ PHP NEWS - MySQLnd: . Fixed field_count not resetting on OK packet. (Kamil Tekiela) + . Fixed memory leak when closing a prepared statement after its connection + was killed. (Kamil Tekiela) - Opcache: . Fixed OSS-Fuzz #546798343 (Heap-buffer-overflow in optimizer with diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index a8a75eff7086..daabc2e72bae 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -115,7 +115,6 @@ void php_clear_stmt_bind(MY_STMT *stmt) if (stmt->stmt) { if (mysqli_stmt_close(stmt->stmt, true)) { php_error_docref(NULL, E_WARNING, "Error occurred while closing statement"); - return; } } diff --git a/ext/mysqli/tests/mysqli_stmt_close_killed_connection.phpt b/ext/mysqli/tests/mysqli_stmt_close_killed_connection.phpt new file mode 100644 index 000000000000..8b573a7666cb --- /dev/null +++ b/ext/mysqli/tests/mysqli_stmt_close_killed_connection.phpt @@ -0,0 +1,32 @@ +--TEST-- +Closing a prepared statement after its connection was killed must not leak +--EXTENSIONS-- +mysqli +--SKIPIF-- +<?php +require_once 'skipifconnectfailure.inc'; +?> +--FILE-- +<?php +require_once 'connect.inc'; + +mysqli_report(MYSQLI_REPORT_OFF); +$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); + +$stmts = []; +for ($i = 0; $i < 20; $i++) { + $stmts[] = $link->prepare('DO 1'); +} +$link->query('KILL ' . $link->thread_id); + +// Over TCP, a few COM_STMT_CLOSE writes may be accepted before one fails +do { + array_pop($stmts); + usleep(1000); +} while ($stmts && !$link->errno); + +echo "done!\n"; +?> +--EXPECTF-- +Warning: main(): Error occurred while closing statement in %s on line %d +done! diff --git a/ext/mysqlnd/mysqlnd_ps.c b/ext/mysqlnd/mysqlnd_ps.c index 681c8f2a4603..9254c58e58d7 100644 --- a/ext/mysqlnd/mysqlnd_ps.c +++ b/ext/mysqlnd/mysqlnd_ps.c @@ -1758,6 +1758,7 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_stmt, close_on_server)(MYSQLND_STMT * const s, bo MYSQLND_STMT_DATA * stmt = s? s->data : NULL; MYSQLND_CONN_DATA * conn = stmt? stmt->conn : NULL; enum_mysqlnd_collected_stats statistic = STAT_LAST; + enum_func_status ret = PASS; DBG_ENTER("mysqlnd_stmt::close_on_server"); if (!stmt || !conn) { @@ -1795,14 +1796,7 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_stmt, close_on_server)(MYSQLND_STMT * const s, bo STAT_FREE_RESULT_EXPLICIT); if (GET_CONNECTION_STATE(&conn->state) == CONN_READY) { - enum_func_status ret = FAIL; - const size_t stmt_id = stmt->stmt_id; - - ret = conn->command->stmt_close(conn, stmt_id); - if (ret == FAIL) { - COPY_CLIENT_ERROR(stmt->error_info, *conn->error_info); - DBG_RETURN(FAIL); - } + ret = conn->command->stmt_close(conn, stmt->stmt_id); } } switch (stmt->execute_count) { @@ -1831,7 +1825,7 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_stmt, close_on_server)(MYSQLND_STMT * const s, bo stmt->conn = NULL; } - DBG_RETURN(PASS); + DBG_RETURN(ret); } /* }}} */

« previous php.cvs (#141702) next »