[php-src] PR #25944: Use `opline_before_exception` in GC tmpvar helpers

From: Date: Mon, 30 Nov 2026 13:31:17 +0000
Subject: [php-src] PR #25944: Use `opline_before_exception` in GC tmpvar helpers
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41252@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25944 Author: realFlowControl When an exception is pending on a user frame, ex->opline points to EG(exception_op) (ZEND_HANDLE_EXCEPTION) rather than into ex->func->op_array.opcodes. Both GC tmpvar helpers unconditionally computed ex->opline - ex->func->op_array.opcodes, which is undefined behavior and produces an out-of-range op_num that skips all live ranges on that frame. In practice, this leaks memory when automatic GC runs directly from a user opcode and a collected object's destructor throws. By the time zend_gc_check_root_tmpvars() runs at the end of zend_gc_collect_cycles(), ex->opline is already EG(exception_op), so live ZEND_LIVE_TMPVAR and ZEND_LIVE_LOOP slots are not re-added to the GC root buffer. Exception unwinding then frees those slots with zval_ptr_dtor_nogc(), leaving any cyclic value kept alive only by a foreach loop tmpvar unreachable. zend_gc_remove_root_tmpvars() hits the same invalid subtraction if GC triggers during ZEND_HANDLE_EXCEPTION.

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