From 845bc4a3cba18d108b20267dff1a87871ed31429 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Jan 2022 09:28:31 +0900 Subject: [PATCH 1/2] fix: DownloadResponse memory leak --- system/CodeIgniter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 3ff821585e6c..ecd051273c75 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -894,6 +894,11 @@ protected function gatherOutput(?Cache $cacheConfig = null, $returned = null) } if ($returned instanceof DownloadResponse) { + // Turn off output buffering completely, even if php.ini output_buffering is not off + while (ob_get_level() > 0) { + ob_end_clean(); + } + $this->response = $returned; return; From 5106920fcde186d8f36fb3f556e9de7245e0e9d4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Jan 2022 09:29:47 +0900 Subject: [PATCH 2/2] perf: reduce memory consumption --- system/HTTP/DownloadResponse.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index 8efb8b47a55a..abd666fbca52 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -306,6 +306,7 @@ private function sendBodyByFilePath() // Flush 1MB chunks of data while (! $splFileObject->eof() && ($data = $splFileObject->fread(1_048_576)) !== false) { echo $data; + unset($data); } return $this;