Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-17122: memory leak in regex #17132

Open
wants to merge 2 commits into
base: PHP-8.4
Choose a base branch
from
Open

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Dec 12, 2024

Because the subpattern names are persistent, and the fact that the symbol table destruction is skipped when using fast_shutdown, this means the refcounts will not be updated for the destruction of the arrays that hold the subpattern name keys.
To solve this, detect this situation and duplicate the strings.
An alternative is always destroying the symbol table, but that changes engine behaviour.
New solution: see below

@nielsdos nielsdos linked an issue Dec 12, 2024 that may be closed by this pull request
Because the subpattern names are persistent, and the fact that the
symbol table destruction is skipped when using fast_shutdown,
this means the refcounts will not be updated for the destruction of
the arrays that hold the subpattern name keys.
To solve this, detect this situation and duplicate the strings.
@nielsdos nielsdos marked this pull request as ready for review December 12, 2024 19:51
@nielsdos nielsdos requested a review from iluuu1994 December 12, 2024 19:57
@nielsdos
Copy link
Member Author

Actually a thought just occurred to me. Since the subpattern names are destroyed during mshutdown we could just use zend_string_free instead of zend_string_release and then we don't have to do this dance...

@bwoebi
Copy link
Member

bwoebi commented Dec 12, 2024

@nielsdos If I see this correctly, the subpatterns are actually never freed at runtime. So yes, this sounds like we just don't care about refcounting and can unconditionally release them later. I prefer that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

memory leak in regex
2 participants