Skip to content

A foreach over a cell array value whose body writes new keys into that same value leaks the value's buffers. #151

Closed

Description

@blacktrs

Summary

A foreach over a cell array value whose body writes new keys into that same value leaks the value's buffers.

Repro

<?php
function make(): array
{
    return [0 => ['a' => 1, 'b' => 'x']];
}
function churn(int $n): int
{
    $c = 0;
    for ($i = 0; $i < $n; $i++) {
        foreach (array_reverse(make(), true) as $element) {
            foreach ($element as $k => $v) {
                $element[$k . 'x'] = $v;
            }
            $c += count($element);
        }
    }
    return $c;
}
churn(2000);
$before = memory_get_peak_usage();
churn(200000);
echo memory_get_peak_usage() - $before < 2 << 20 ? "flat\n" : "grows\n";

Expected (php)

flat

Actual (manticore aa8790fb, Darwin arm64)

grows

Tracking

Known-bug repro: tests/aot/repro/leak/foreach_over_cell_value_while_writing_it_leaks.php — bash tests/aot/xfail.sh -k foreach_over_cell_value_while_writing_it_leaks reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    leak
    on Oct 8, 2026
  2. added 2 commits that reference this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugleak

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions