From bd21b7f96634c85c6f269569a0546d9d2670b462 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 15 Jun 2018 09:17:50 +0300 Subject: [PATCH] Fixed image resource memory deallocation (part 2) [#2045] --- system/src/Grav/Common/Page/Medium/ImageFile.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Page/Medium/ImageFile.php b/system/src/Grav/Common/Page/Medium/ImageFile.php index 3727ee9e70..85f2459ede 100644 --- a/system/src/Grav/Common/Page/Medium/ImageFile.php +++ b/system/src/Grav/Common/Page/Medium/ImageFile.php @@ -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 @@ -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 @@ -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); } @@ -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; }