Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DownloadResponse memory leak #5623

Merged
merged 2 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions system/HTTP/DownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down