Commit 204a181165b for php

commit 204a181165bf847bae51e9565b32216abba7d1e1
Author: lacatoire <la.catoire@gmail.com>
Date:   Mon Nov 16 14:28:46 2026 +0100

    ext/spl: Fix leak of the static variables of a file loaded by spl_autoload()

    spl_autoload() destroyed the op array of the loaded file without freeing
    its static variables, unlike eval and the main script. A top-level
    static in an autoloaded file leaked.

    Close GH-25484

diff --git a/NEWS b/NEWS
index 89f42df859b..b74d9704a06 100644
--- a/NEWS
+++ b/NEWS
@@ -131,6 +131,10 @@ PHP                                                                        NEWS
   . Fixed socket_addrinfo_lookup() rejecting an empty packed hints array.
     (lacatoire)

+- SPL:
+  . Fixed memory leak of the static variables of a file loaded by
+    spl_autoload(). (lacatoire)
+
 - Standard:
   . Fixed bug GH-25474 (version_compare() treats large numeric parts as equal
     on 64-bit Windows). (lazerg)
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index 6bcf5b6cda3..fdb01b3f08d 100644
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -262,6 +262,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha
 			zend_execute(new_op_array, &result);
 			EG(jit_trace_num) = orig_jit_trace_num;

+			zend_destroy_static_vars(new_op_array);
 			destroy_op_array(new_op_array);
 			efree(new_op_array);
 			if (!EG(exception)) {
diff --git a/ext/spl/tests/spl_autoload_static_variable_leak.phpt b/ext/spl/tests/spl_autoload_static_variable_leak.phpt
new file mode 100644
index 00000000000..92e390fcc53
--- /dev/null
+++ b/ext/spl/tests/spl_autoload_static_variable_leak.phpt
@@ -0,0 +1,22 @@
+--TEST--
+spl_autoload() frees the static variables of the autoloaded file
+--INI--
+report_memleaks=1
+--FILE--
+<?php
+$dir = __DIR__ . '/spl_autoload_static_variable_leak_dir';
+mkdir($dir);
+set_include_path($dir);
+file_put_contents($dir . '/stat1.php', '<?php static $top = [1, 2, 3]; class Stat1 {}');
+
+spl_autoload('Stat1');
+var_dump(class_exists('Stat1', false));
+?>
+--CLEAN--
+<?php
+$dir = __DIR__ . '/spl_autoload_static_variable_leak_dir';
+@unlink($dir . '/stat1.php');
+@rmdir($dir);
+?>
+--EXPECT--
+bool(true)