Skip to content

memory leak when using fopen with a stream wrapper #8548

@manueldimmler

Description

@manueldimmler

Description

The following code takes up a lot of memory and keeps increasing in a endless loop:

#!/usr/bin/php
<?php

class Wrapper
{

    public function stream_open(string $path, string $mode, int $options): bool
    {
        return true;
    }

}

$filename = tempnam(__DIR__, '');
touch($filename);

$wrapper = new Wrapper();
$counter = 0;
while ($counter < 1_000_000) {
    $counter++;
    stream_wrapper_register('symfony', Wrapper::class);
    fopen('symfony://' . $filename, 'r');
    stream_wrapper_unregister('symfony');
}

memory_leak_01

With a small change, the problem disappears:

#!/usr/bin/php
<?php

class Wrapper
{

    public function stream_open(string $path, string $mode, int $options): bool
    {
        return true;
    }

}

$filename = tempnam(__DIR__, '');
touch($filename);

$wrapper = new Wrapper();
$counter = 0;
stream_wrapper_register('symfony', Wrapper::class);
while ($counter < 1_000_000) {
    $counter++;
    fopen('symfony://' . $filename, 'r');
}
stream_wrapper_unregister('symfony');

memory_leak_02

The memory leak was described in the following ticket: symfony/symfony#46256

PHP Version

PHP 8.1.5 (cli)

Operating System

Ubuntu 20.04

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy