Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 913c1fd

Browse files
committed
bug #26727 [HttpCache] Unlink tmp file on error (Chansig)
This PR was merged into the 2.7 branch. Discussion ---------- [HttpCache] Unlink tmp file on error | Q | A | ------------- | --- | Branch? | 2.7 up to 4.0 for bug fixes <!-- see below --> | Bug fix? | yes | New feature? |no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #22719 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> The tempnam function creates a unique temporary file for each call to a page to be cached, and if the temporary folder passed as an argument is not writable, tempnam will use /tmp. _Note: If PHP cannot create a file in the specified dir parameter, it falls back on the system default. On NTFS this also happens if the specified dir contains more than 65534 files. http://php.net/manual/en/function.tempnam.php_ Therefore, as soon as the HttpCache cache is no longer writable, the /tmp fills up fairly quickly, tempnam being called on every page (since no page cache) and creating a new unique file in /tmp. See #22719 Commits ------- c9a0355 [HttpCache] Unlink tmp file on error
2 parents 509142e + c9a0355 commit 913c1fd

File tree

1 file changed

+6
-0
lines changed
  • src/Symfony/Component/HttpKernel/HttpCache

1 file changed

+6
-0
lines changed

src/Symfony/Component/HttpKernel/HttpCache/Store.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,22 @@ private function save($key, $data)
387387

388388
$tmpFile = tempnam(dirname($path), basename($path));
389389
if (false === $fp = @fopen($tmpFile, 'wb')) {
390+
@unlink($tmpFile);
391+
390392
return false;
391393
}
392394
@fwrite($fp, $data);
393395
@fclose($fp);
394396

395397
if ($data != file_get_contents($tmpFile)) {
398+
@unlink($tmpFile);
399+
396400
return false;
397401
}
398402

399403
if (false === @rename($tmpFile, $path)) {
404+
@unlink($tmpFile);
405+
400406
return false;
401407
}
402408
}

0 commit comments

Comments
 (0)