`eval` is leaking memory
Open
Nobody has claimed this yet.
Bug
Category: Engine
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
$m = memory_get_usage();
for ($i = 0; $i < 1000; $i++) {
$fn = eval('return function ($foo) {};');
//$fn = function ($foo) {};
var_dump(memory_get_usage() - $m);
}
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:
int(640)
int(672)
int(672)
int(672)
...
int(197280)
But I expected this output instead:
int(640)
int(672)
int(672)
int(672)
...
int(672)
PHP Version
8.1.x
Operating System
any
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided PHP 8.1 reproduction and compare its memory usage with the direct-closure and eval-without-anonymous-function examples linked in the issue. Trace the eval path responsible for creating anonymous functions; done means repeated evaluations no longer show steadily increasing memory usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100