-
Notifications
You must be signed in to change notification settings - Fork 7.9k
eval
is leaking memory
#8078
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
Comments
This is by design - for now at least. This is not specific to eval, but to any non-top level op_array (i.e. all functions). Generally, code, once compiled - unless it is top level code - is persisted for the request. For example, this also leaks:
with
But we do currently not have any mechanisms to track unresolved (or Closure) op_arrays (and classes) by their parent op_array to free them on destruction (in this case, triggered by: eval or inclusion returning). |
@bwoebi As of PHP 8.1 we do actually. We track these via dynamic_func_defs and release them once unused. The only reason there is still a small leak here, is that the op_array structure itself is still arena-allocated. Edit: This doesn't apply to classes -- classes are much harder to fix due to preloading, which makes everything very complicated. |
is the freeing of the arena-allocated op_array structure for the closure easily fixable? |
Arena allocations are similar to SQL transactions with checkpoints. You can destroy the whole arena or roll back to a certain checkpoint, but you can't free certain parts of the arena. So I don't think this is (easily) fixable. |
It requires moving away from arena allocation. I believe it's not entirely simple because we have two different ways to share op_arrays, one of them sharing only the resources it points to while having a separately allocated op_array structure, and another where the op_array itself is also shared. This makes it a bit tricky to determine whether or not an op_array needs to be freed when it is released, or only the refcount decremented. |
Description
The following code:
https://3v4l.org/LF4Ri
https://3v4l.org/1DeC6 - /wo eval, not leaking
https://3v4l.org/NtIrU - eval /wo anonymous function is not leaking
Resulted in this output:
But I expected this output instead:
PHP Version
8.1.x
Operating System
any
The text was updated successfully, but these errors were encountered: