Skip to content

ext/standard: Release lc_needle on OOM in php_str_to_str_i_ex() - #487

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
fix/str-ireplace-oom-leak-84
Closed

iliaal wants to merge 1 commit into
PHP-8.4from
fix/str-ireplace-oom-leak-84

Conversation

@iliaal

@iliaal iliaal commented Nov 27, 2026

Copy link
Copy Markdown
Owner

When zend_string_safe_falloc() fails under memory_limit in php_str_to_str_i_ex(), the early return skips zend_string_release_ex(lc_needle, 0), leaking the lowercased needle string allocated by zend_string_tolower() (introduced in 3584a98).

Release lc_needle before returning NULL.

Verified red-before (503,976 bytes leaked for a 500 KB needle in shutdown memory_get_usage()) and green-after on PHP-8.4 debug build.

When zend_string_safe_falloc() fails under memory_limit,
php_str_to_str_i_ex() returned NULL without releasing the lowercased needle.
@iliaal
iliaal force-pushed the fix/str-ireplace-oom-leak-84 branch from a0baf64 to 2f9d10c Compare November 27, 2026 16:46
@iliaal

iliaal commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php/php-src phpGH-25848: php#25848

@iliaal iliaal closed this Nov 27, 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