Skip to content

An array property passed by reference through an erased (mixed) receiver leaks the property's array on every call. #138

Closed

Description

@blacktrs

Summary

An array property passed by reference through an erased (mixed) receiver leaks the property's array on every call.

Repro

<?php
final class D
{
    public static int $live = 0;
    public function __construct() { self::$live++; }
    public function __destruct() { self::$live--; }
}
final class Bucket
{
    /** @var D[] */
    public array $arr = [];
}
final class Sink
{
    /** @param D[] $out */
    public function f(array &$out): int { $out[] = new D(); return count($out); }
}
function feed(Sink $s, mixed $o): int { return $s->f($o->arr); }
$s = new Sink();
for ($i = 0; $i < 1000; $i++) {
    $c = new Bucket();
    $c->arr[] = new D();
    feed($s, $c);
}
$c = null;
echo D::$live === 0 ? "flat\n" : "leaks " . D::$live . "\n";

Expected (php)

flat

Actual (manticore c60903c2, Darwin arm64)

leaks 1000

Tracking

Known-bug repro: tests/aot/repro/leak/byref_erased_receiver_prop_leaks.php — bash tests/aot/xfail.sh -k byref_erased_receiver_prop_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.

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