Skip to content

[HttpClient] CurlHttpClient keep reference to resources passed by form data #60506

@alex-dev

Description

@alex-dev

Symfony version(s) affected

Confirmed for 6.4

Description

When using form data and resources, CurlHttpClient leaks the resource. It is likely kept alive by a CurlHandle at that point.

How to reproduce

<?php

use Symfony\Component\HttpClient\CurlHttpClient;

require_once __DIR__ . '/vendor/autoload.php';

$client = new CurlHttpClient();
$data = fopen('php://memory', 'r+');
$canary = fopen('php://memory', 'r+');
fwrite($data, random_bytes(1024));
fwrite($canary, random_bytes(1024));
rewind($data);
rewind($canary);

$client->request('POST', 'http://127.0.0.1:8061/imports', ['body' => ['data' => $data]]);
dump(array_map(stream_get_meta_data(...), get_resources('stream')));

unset($data);
unset($canary);
dump(array_map(stream_get_meta_data(...), get_resources('stream')));

$client->reset();
dump(array_map(stream_get_meta_data(...), get_resources('stream')));

Each dump return the resource held by $data. The resource held by $canary is only returned by the first dump.
Do note that passing the resource as body (e.g. ['body' => $data]) works as expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions