[php-src] master: ext/spl: Fix leak of the static variables of a file loaded by spl_autoload()

From: Date: Wed, 18 Nov 2026 06:14:13 +0000
Subject: [php-src] master: ext/spl: Fix leak of the static variables of a file loaded by spl_autoload()
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143819@lists.php.net to get a copy of this message
Author: lacatoire (lacatoire) Committer: David Carlier (devnexen) Date: 2026-11-18T06:12:53Z Commit: https://github.com/php/php-src/commit/204a181165bf847bae51e9565b32216abba7d1e1 Raw diff: https://github.com/php/php-src/commit/204a181165bf847bae51e9565b32216abba7d1e1.diff 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 Changed paths: A ext/spl/tests/spl_autoload_static_variable_leak.phpt M NEWS M ext/spl/php_spl.c Diff: diff --git a/NEWS b/NEWS index 89f42df859bf..b74d9704a06d 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 6bcf5b6cda38..fdb01b3f08db 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 000000000000..92e390fcc534 --- /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)

« previous php.cvs (#143819) next »