From: joshuaruesweg Date: Wed, 21 Apr 2021 09:20:27 +0000 (+0200) Subject: Always close Guzzle response body after reading it X-Git-Tag: 5.4.0_Alpha_1~12^2~9^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=364739c377fdeb355debf4872d23f24603441bd3;p=GitHub%2FWoltLab%2FWCF.git Always close Guzzle response body after reading it --- diff --git a/wcfsetup/install/files/lib/util/HTTPRequest.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php index efcc294c20..2cb85ab067 100644 --- a/wcfsetup/install/files/lib/util/HTTPRequest.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -284,22 +284,27 @@ final class HTTPRequest { } if ($this->replyBody === null) { - $bodyLength = 0; - while (!$this->response->getBody()->eof()) { - $toRead = 8192; - if (isset($this->options['maxLength'])) { - $toRead = min($toRead, $this->options['maxLength'] - $bodyLength); - } - - $data = $this->response->getBody()->read($toRead); - $this->replyBody .= $data; - $bodyLength += strlen($data); - - if (isset($this->options['maxLength']) && $bodyLength >= $this->options['maxLength']) { - $this->response->getBody()->close(); - break; - } + try { + $bodyLength = 0; + while (!$this->response->getBody()->eof()) { + $toRead = 8192; + if (isset($this->options['maxLength'])) { + $toRead = min($toRead, $this->options['maxLength'] - $bodyLength); + } + + $data = $this->response->getBody()->read($toRead); + $this->replyBody .= $data; + $bodyLength += strlen($data); + + if (isset($this->options['maxLength']) && $bodyLength >= $this->options['maxLength']) { + break; + } + } } + finally { + $this->response->getBody()->close(); + } + if (isset($this->options['maxLength'])) { $this->replyBody = substr($this->replyBody, 0, $this->options['maxLength']); }