From 364739c377fdeb355debf4872d23f24603441bd3 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Wed, 21 Apr 2021 11:20:27 +0200 Subject: [PATCH] Always close Guzzle response body after reading it --- .../files/lib/util/HTTPRequest.class.php | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) 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']); } -- 2.20.1