Skip to content

Commit 16d0176

Browse files
[HttpClient] Fix memory leak when using StreamWrapper
1 parent 42938ef commit 16d0176

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/Symfony/Component/HttpClient/Response/StreamWrapper.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,18 @@ public static function createResource(ResponseInterface $response, HttpClientInt
5353
throw new \InvalidArgumentException(sprintf('Providing a client to "%s()" is required when the response doesn\'t have any "stream()" method.', __CLASS__));
5454
}
5555

56-
if (false === stream_wrapper_register('symfony', __CLASS__)) {
56+
static $registered = false;
57+
58+
if (!$registered = $registered || stream_wrapper_register(strtr(__CLASS__, '\\', '-'), __CLASS__)) {
5759
throw new \RuntimeException(error_get_last()['message'] ?? 'Registering the "symfony" stream wrapper failed.');
5860
}
5961

60-
try {
61-
$context = [
62-
'client' => $client ?? $response,
63-
'response' => $response,
64-
];
65-
66-
return fopen('symfony://'.$response->getInfo('url'), 'r', false, stream_context_create(['symfony' => $context])) ?: null;
67-
} finally {
68-
stream_wrapper_unregister('symfony');
69-
}
62+
$context = [
63+
'client' => $client ?? $response,
64+
'response' => $response,
65+
];
66+
67+
return fopen(strtr(__CLASS__, '\\', '-').'://'.$response->getInfo('url'), 'r', false, stream_context_create(['symfony' => $context]));
7068
}
7169

7270
public function getResponse(): ResponseInterface

0 commit comments

Comments
 (0)
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