Merge pull request #22121 from nextcloud/backport/22008/stable19

[stable19] Ensured large image is unloaded from memory when generating previews
This commit is contained in:
Roeland Jago Douma 2020-08-13 05:23:01 +02:00 committed by GitHub
commit 92d0f5e7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View 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 \OC_Image) {
$maxPreviewImage->destroy();
}
return $preview; return $preview;
} }

View File

@ -31,7 +31,6 @@ use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder; use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig; use OCP\IConfig;
use OCP\IImage;
use OCP\IPreview; use OCP\IPreview;
use OCP\Preview\IProviderV2; use OCP\Preview\IProviderV2;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -183,7 +182,7 @@ class GeneratorTest extends \Test\TestCase {
$this->fail('Unexpected provider requested'); $this->fail('Unexpected provider requested');
}); });
$image = $this->createMock(IImage::class); $image = $this->createMock(\OC_Image::class);
$image->method('width')->willReturn(2048); $image->method('width')->willReturn(2048);
$image->method('height')->willReturn(2048); $image->method('height')->willReturn(2048);
$image->method('valid')->willReturn(true); $image->method('valid')->willReturn(true);
@ -318,7 +317,7 @@ class GeneratorTest extends \Test\TestCase {
} }
private function getMockImage($width, $height, $data = null) { 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('height')->willReturn($width);
$image->method('width')->willReturn($height); $image->method('width')->willReturn($height);
$image->method('valid')->willReturn(true); $image->method('valid')->willReturn(true);