Skip to content

Commit

Permalink
Fixed image resource memory deallocation (part 2) [#2045]
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jun 15, 2018
1 parent 021fbb8 commit bd21b7f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions system/src/Grav/Common/Page/Medium/ImageFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Grav\Common\Grav;
use Gregwar\Image\Exceptions\GenerationError;
use Gregwar\Image\Image;
use Gregwar\Image\Source;
use RocketTheme\Toolbox\Event\Event;

class ImageFile extends Image
Expand Down Expand Up @@ -65,7 +66,6 @@ public function cacheFile($type = 'jpg', $quality = 80, $actual = false)
$cacheFile .= $this->prettyName;
}


$cacheFile .= '.' . $type;

// If the files does not exists, save it
Expand All @@ -81,8 +81,6 @@ public function cacheFile($type = 'jpg', $quality = 80, $actual = false)
$generate = function ($target) use ($image, $type, $quality) {
$result = $image->save($target, $type, $quality);

$image->getAdapter()->deinit();

if ($result !== $target) {
throw new GenerationError($result);
}
Expand All @@ -94,11 +92,15 @@ public function cacheFile($type = 'jpg', $quality = 80, $actual = false)
try {
$perms = Grav::instance()['config']->get('system.images.cache_perms', '0755');
$perms = octdec($perms);
$file = $this->cache->setDirectoryMode($perms)->getOrCreateFile($cacheFile, $conditions, $generate, $actual);
$file = $this->getCacheSystem()->setDirectoryMode($perms)->getOrCreateFile($cacheFile, $conditions, $generate, $actual);
} catch (GenerationError $e) {
$file = $e->getNewFile();
}

// Nulling the resource
$this->getAdapter()->setSource(new Source\File($file));
$this->getAdapter()->deinit();

if ($actual) {
return $file;
}
Expand Down

0 comments on commit bd21b7f

Please sign in to comment.