Skip to content

[intl] fix leak when iterating IntlBreakIterator parts iterators - #279

Open
iliaal wants to merge 1 commit into
PHP-8.4from
fix/intl-enum-current-leak-84
Open

[intl] fix leak when iterating IntlBreakIterator parts iterators#279
iliaal wants to merge 1 commit into
PHP-8.4from
fix/intl-enum-current-leak-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Iterating the result of IntlBreakIterator::getPartsIterator() leaked memory on every loop because the IntlPartsIterator object held a counted self-reference through its embedded zend_object_iterator's wrapping_obj, so refcount destruction could never complete; the retained current element was additionally never released at iterator destruction. This makes zoi_with_current_dtor() invalidate the current element and leaves the parts iterator's wrapping_obj UNDEF (as the plain BreakIterator iterator already does), so teardown is now deterministic: repeated 300k-iteration loops went from leaking about 85 MB to a flat zero-delta profile, verified by a new phpt that fails on unpatched builds. Sibling audit: the StringEnumeration iterator path still requires wrapping_obj for owner error handling in move_forward/rewind and keeps its self-reference, and ResourceBundle uses an independent iterator implementation.

Iterating a parts iterator left the IntlPartsIterator object holding a
counted self-reference through the embedded zend_object_iterator's
wrapping_obj, so refcount destruction could never complete and every
getPartsIterator() loop leaked the iterator object, its wrapper and the
retained current element.

zoi_with_current_dtor() now also invalidates the current element, and
the parts iterator no longer addrefs itself (wrapping_obj stays UNDEF as
in the plain BreakIterator iterator), making teardown deterministic.

Sibling audit: string_enum_object_iterator_funcs still requires
wrapping_obj for owner error handling in move_forward/rewind and keeps
its self-reference; ResourceBundle uses an independent iterator
implementation and is unaffected.
@iliaal iliaal closed this Aug 24, 2026
@iliaal iliaal reopened this Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant