Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 16d0176

Browse filesBrowse files
[HttpClient] Fix memory leak when using StreamWrapper
1 parent 42938ef commit 16d0176
Copy full SHA for 16d0176

File tree

Expand file treeCollapse file tree

1 file changed

+9
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-11
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/StreamWrapper.php
+9-11Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.