Skip to content

Commit

Permalink
Merge pull request #30533 from owncloud/stable10-a-pack-of-fclose
Browse files Browse the repository at this point in the history
[Stable10] Free resources in preview providers
  • Loading branch information
Vincent Petry authored Feb 20, 2018
2 parents e57b07a + c4ef964 commit b7d5556
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/private/Preview/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
// in some cases 1MB was no enough to generate thumbnail
$firstmb = stream_get_contents($handle, 5242880);
file_put_contents($absPath, $firstmb);
fclose($handle);
}

$result = $this->generateThumbNail($maxX, $maxY, $absPath, 5);
Expand Down
4 changes: 3 additions & 1 deletion lib/private/Preview/SVG.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
$svg = new \Imagick();
$svg->setBackgroundColor(new \ImagickPixel('transparent'));

$content = stream_get_contents($fileview->fopen($path, 'r'));
$stream = $fileview->fopen($path, 'r');
$content = stream_get_contents($stream);
if (substr($content, 0, 5) !== '<?xml') {
$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
}
fclose($stream);

// Do not parse SVG files with references
if (stripos($content, 'xlink:href') !== false) {
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Preview/TXT.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public function isAvailable(\OCP\Files\FileInfo $file) {
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
$content = $fileview->fopen($path, 'r');
$content = stream_get_contents($content,3000);
$stream = $fileview->fopen($path, 'r');
$content = stream_get_contents($stream,3000);
fclose($stream);

//don't create previews of empty text files
if(trim($content) === '') {
Expand Down

0 comments on commit b7d5556

Please sign in to comment.