[php-src] PR #25830: Fix leak of a hooked property value when the get hook throws in var_export() and get_object_vars()

From: Date: Fri, 27 Nov 2026 10:24:02 +0000
Subject: [php-src] PR #25830: Fix leak of a hooked property value when the get hook throws in var_export() and get_object_vars()
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41103@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25830 Author: lacatoire var_export() and get_object_vars() read a hooked property into a local zval and bail out when an exception is pending, without releasing it. The get hook can fill that zval and still throw while its frame is freed, for example from the destructor of one of its locals. GH-22919 fixed the same leak in json_encode(); this applies the same fix to the two other readers. ### To reproduce ```php <?php class Thrower { function __destruct() { throw new Exception('destructor'); } } class Hooked { public string $prop { get { $local = new Thrower; return str_repeat('y', 100000); } } } foreach (['json_encode', 'var_export', 'get_object_vars'] as $function) { $export = fn() => $function === 'var_export' ? var_export(new Hooked, true) : $function(new Hooked); try { $export(); } catch (Exception $e) {} $before = memory_get_usage(); for ($i = 0; $i < 100; $i++) { try { $export(); } catch (Exception $e) {} } printf("%s: %d bytes\n", $function, memory_get_usage() - $before); } ``` Before (8.4.28, 8.5.13): ``` json_encode: 0 bytes var_export: 10240000 bytes get_object_vars: 10240000 bytes ``` After: ``` json_encode: 0 bytes var_export: 0 bytes get_object_vars: 0 bytes ```

« previous php.git-pulls (#41103) next »