Skip to content

A get hook returning a freshly built string leaks it when read through a typed, union or erased receiver. #460

Closed

Description

@blacktrs

Summary

A get hook returning a freshly built string leaks it when read through a typed, union or erased receiver.

Repro

<?php
final class A { public int $n = 1; public string $s { get => str_repeat('x', 16384) . $this->n; } }
final class C { public string $s = 'c'; }
function make(): A|false { return new A(); }
function viaMixed(mixed $o): int { return strlen($o->s); }
$a = new A();
$u = make();
$m0 = memory_get_peak_usage();
$t = 0;
for ($i = 0; $i < 2000; $i++) {
    $t += strlen($a->s) + strlen($u->s) + viaMixed($i % 2 ? $a : new C());
}
$mb = (memory_get_peak_usage() - $m0) >> 20;
fwrite(STDERR, "grew {$mb} MB\n");
echo $t > 0 && $mb < 8 ? "flat\n" : "LEAK\n";

Expected (php)

flat

Actual (manticore dc3883d9, Darwin arm64)

LEAK
(stderr: grew 104 MB)

Tracking

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