[php-src] PHP-8.6: Fix GH-23626: OPcache: orphaned temporaries cause leaks and assertions
| From: | ndossche | Date: | Wed, 28 Oct 2026 22:25:02 +0000 |
| Subject: | [php-src] PHP-8.6: Fix GH-23626: OPcache: orphaned temporaries cause leaks and assertions | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142907@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-10-28T23:23:52+01:00
Commit: https://github.com/php/php-src/commit/c7ea9b17582dc4c0e39249ec5860dea62abe8728
Raw diff: https://github.com/php/php-src/commit/c7ea9b17582dc4c0e39249ec5860dea62abe8728.diff
Fix GH-23626: OPcache: orphaned temporaries cause leaks and assertions
Closes GH-24069.
Co-authored-by: Khaled Alam <khaledalam.net@gmail.com>
Changed paths:
A ext/opcache/tests/gh23626.phpt
M NEWS
M Zend/zend_compile.c
Diff:
diff --git a/NEWS b/NEWS
index c1c0c03b7117..8f2839bd8bf3 100644
--- a/NEWS
+++ b/NEWS
@@ -170,6 +170,8 @@ PHP NEWS
. Fixed AArch64 JIT encoding of invalid logical immediates. (jorgsowa)
. Fixed unsound shift_left_overflows range when shift wraps. (mkrishna793)
. Fix block pass dropping ZEND_FAST_CALL OP2 definition. (Mrmaxmeier)
+ . Fixed bug GH-23626 (orphaned temporaries cause leaks and assertions).
+ (ndossche, khaledalam)
- OpenSSL:
. Fixed bug GH-24784 (openssl_pkcs7_read() and openssl_cms_read() overwrite
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 84267c1e7ee4..7e7e602f5895 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -6546,10 +6546,9 @@ static void zend_compile_match(znode *result, zend_ast *ast)
if (opline->op1_type == IS_CONST) {
Z_TRY_ADDREF_P(CT_CONSTANT(opline->op1));
}
- if (arms->children == 0) {
- /* Mark this as an "expression throw" for opcache. */
- opline->extended_value = ZEND_THROW_IS_EXPR;
- }
+ /* Mark this as an "expression throw" for opcache.
+ * Even if there are arms, they may become unreachable after optimization, which loses live
ranges. */
+ opline->extended_value = ZEND_THROW_IS_EXPR;
}
for (uint32_t i = 0; i < arms->children; ++i) {
diff --git a/ext/opcache/tests/gh23626.phpt b/ext/opcache/tests/gh23626.phpt
new file mode 100644
index 000000000000..67e20da9def5
--- /dev/null
+++ b/ext/opcache/tests/gh23626.phpt
@@ -0,0 +1,59 @@
+--TEST--
+GH-23626: OPcache: orphaned temporaries cause leaks and assertions
+--CREDITS--
+Mrmaxmeier
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--FILE--
+<?php
+class D {
+ public function __construct(public string $name) {}
+ public function __clone() { $this->name .= '-clone'; }
+ public function __destruct() { echo "destruct {$this->name}\n"; }
+}
+
+function test_assert($u) {
+ (function () use ($u) {}) ** match (1) { 2 => 3 };
+}
+
+function one($o) {
+ (clone $o) ** match (1) { 2 => 3 };
+}
+
+function two($a, $b) {
+ (clone $a) ** ((clone $b) ** match (1) { 2 => 3 });
+}
+
+function rope($o) {
+ return "x{$o->name}y" . match (1) { 2 => 3 };
+}
+
+$a = new D('a');
+$b = new D('b');
+
+foreach (['test_assert' => [1], 'one' => [$a], 'two' => [$a,
$b], 'rope' => [$a]] as $fn => $args) {
+ try {
+ $fn(...$args);
+ } catch (\UnhandledMatchError $e) {
+ echo "$fn: ", $e->getMessage(), "\n";
+ }
+}
+
+unset($a, $b, $args, $e);
+echo "done\n";
+?>
+--EXPECT--
+test_assert: Unhandled match case 1
+destruct a-clone
+one: Unhandled match case 1
+destruct a-clone
+destruct b-clone
+two: Unhandled match case 1
+rope: Unhandled match case 1
+destruct b
+destruct a
+done