[php-src] PR #12538: Fix memory leak in by-ref foreach.
| From: | danog | Date: | Fri, 27 Oct 2023 15:15:40 +0000 |
| Subject: | [php-src] PR #12538: Fix memory leak in by-ref foreach. | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-24009@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/12538
Author: danog
The issue occurs if a circular reference on the array var of a by-ref foreach is created, all
visible references to the array var are removed and the garbage collector is invoked before exiting
the foreach.
Invoking the garbage collector removes the array var from the roots, because the foreach statement
itself is still holding a reference to it and thus it's still alive, but when the foreach ends
it does not re-add the array var to the GC roots, thus the GC cannot collect it and it leaks.
This PR fixes the issue by invoking the GC-aware zval destructor, which correctly adds the zval to
the GC roots.
Fixes oss-fuzz #54515.