Skip to content

Leak: function f(string &$s) { $s .= 'x'; } leaks every old buffer (quadratic) #21

Closed

Description

@blacktrs

Summary

Leak: function f(string &$s) { $s .= 'x'; } leaks every old buffer (quadratic).

Repro

<?php
function f(string &$s): void { $s .= 'x'; }
$m0 = memory_get_peak_usage();
$s = '';
for ($i = 0; $i < 6000; $i++) { f($s); }
$mb = (memory_get_peak_usage() - $m0) >> 20;
fwrite(STDERR, "grew {$mb} MB\n");
echo $mb < 8 ? "flat\n" : "LEAK\n";

The repro measures its own peak RSS (memory_get_peak_usage()) around the loop and prints flat when it grew by less than 8 MB.

Expected (php 8.5)

flat

Actual (manticore 10affa68, macOS arm64)

LEAK
(stderr: grew 20 MB)

Tracking

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