Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable18] Ensured large image is unloaded from memory when generating previews #22186

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false,
throw new NotFoundException('Cached preview size 0, invalid!');
}

// 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;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/lib/Preview/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
use OCP\IImage;
use OCP\IPreview;
use OCP\Preview\IProvider;
use OCP\Preview\IProviderV2;
Expand Down Expand Up @@ -184,7 +183,7 @@ public function testGetNewPreview() {
$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);
Expand Down