Skip to content

Commit

Permalink
Merge pull request #30507 from owncloud/a-pack-of-fclose
Browse files Browse the repository at this point in the history
Free resources in preview providers
  • Loading branch information
Vincent Petry authored Feb 19, 2018
2 parents 0a0d750 + 371f2be commit 3b420d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/private/Preview/Bitmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
} catch (\Exception $e) {
Util::writeLog('core', 'ImageMagick says: ' . $e->getmessage(), Util::ERROR);
return false;
} finally {
fclose($stream);
}

fclose($stream);

//new bitmap image object
$image = new \OC_Image();
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 @@ -42,10 +42,12 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
$svg = new \Imagick();
$svg->setBackgroundColor(new \ImagickPixel('transparent'));

$content = stream_get_contents($file->fopen('r'));
$stream = $file->fopen('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 @@ -40,8 +40,9 @@ public function getMimeType() {
* {@inheritDoc}
*/
public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
$content = $file->fopen('r');
$content = stream_get_contents($content,3000);
$stream = $file->fopen('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 3b420d6

Please sign in to comment.