]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix memory leak caused by not destroying image in Preview/Generate.php
authorElijah Martin-Merrill <elijah@nyp-itsours.com>
Mon, 27 Jul 2020 14:52:44 +0000 (10:52 -0400)
committerElijah Martin-Merrill <elijah@nyp-itsours.com>
Mon, 27 Jul 2020 14:52:44 +0000 (10:52 -0400)
Signed-off-by: Elijah Martin-Merrill <elijah@nyp-itsours.com>
lib/private/Preview/Generator.php
tests/lib/Preview/GeneratorTest.php

index f7aed987d8962f1e39fcb1c6b3c827f8bb1fa5e6..45e991d551da12895d4269fe85474a5837d0afdd 100644 (file)
@@ -192,6 +192,12 @@ class Generator {
                        }
                }
 
+               // Free memory being used by the embedded image resource.  Without this the image is kept in memory indefinitely.
+               // Garbage Collection does NOT free this memory.  We have to do it ourselves.
+               if ($maxPreviewImage instanceof IImage) {
+                       $maxPreviewImage->destroy();
+               }
+
                return $preview;
        }
 
index 3a46447632d11c1758d42c4a2343abcf5869e79c..5e9b9bcbb8dab4973683c536fbeac580df69d7cc 100644 (file)
@@ -31,7 +31,6 @@ use OCP\Files\NotFoundException;
 use OCP\Files\SimpleFS\ISimpleFile;
 use OCP\Files\SimpleFS\ISimpleFolder;
 use OCP\IConfig;
-use OCP\IImage;
 use OCP\IPreview;
 use OCP\Preview\IProviderV2;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -183,7 +182,7 @@ class GeneratorTest extends \Test\TestCase {
                                $this->fail('Unexpected provider requested');
                        });
 
-               $image = $this->createMock(IImage::class);
+               $image = $this->createMock(\OC_Image::class);
                $image->method('width')->willReturn(2048);
                $image->method('height')->willReturn(2048);
                $image->method('valid')->willReturn(true);
@@ -318,7 +317,7 @@ class GeneratorTest extends \Test\TestCase {
        }
 
        private function getMockImage($width, $height, $data = null) {
-               $image = $this->createMock(IImage::class);
+               $image = $this->createMock(\OC_Image::class);
                $image->method('height')->willReturn($width);
                $image->method('width')->willReturn($height);
                $image->method('valid')->willReturn(true);