[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Kamil Tekiela | Date: | Tue, 29 Sep 2026 16:41:56 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141704@lists.php.net to get a copy of this message | ||
Author: Kamil Tekiela (kamil-tekiela)
Date: 2026-09-29T17:39:58+01:00
Commit: https://github.com/php/php-src/commit/69367447d1cfe32eee17a845e1fe773ac73eb1b1
Raw diff: https://github.com/php/php-src/commit/69367447d1cfe32eee17a845e1fe773ac73eb1b1.diff
Merge branch 'PHP-8.5' into PHP-8.6
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 050e35d08c44..b4ebac826d7f 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,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:
. Fix zend_analyze_calls() call_stack buffer overrun. (Mrmaxmeier)
diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c
index 23fd70247fe4..5e6319ae77cc 100644
--- a/ext/mysqli/mysqli.c
+++ b/ext/mysqli/mysqli.c
@@ -111,7 +111,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 d6811457e6b9..522b37e9d813 100644
--- a/ext/mysqlnd/mysqlnd_ps.c
+++ b/ext/mysqlnd/mysqlnd_ps.c
@@ -1756,6 +1756,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) {
@@ -1793,14 +1794,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) {
@@ -1829,7 +1823,7 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_stmt, close_on_server)(MYSQLND_STMT * const s,
bo
stmt->conn = NULL;
}
- DBG_RETURN(PASS);
+ DBG_RETURN(ret);
}
/* }}} */