Skip to content

Commit 25c2131

Browse files
bug #47143 [HttpClient] Fix memory leak when using StreamWrapper (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Fix memory leak when using StreamWrapper | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46256 | License | MIT | Doc PR | - As hinted in php/php-src#8548 Commits ------- 16d0176 [HttpClient] Fix memory leak when using StreamWrapper
2 parents 6c0f7da + 16d0176 commit 25c2131

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