From 74ad26fee64a99c8e37c14ab5c69956ada4edb68 Mon Sep 17 00:00:00 2001 From: Emelia Smith Date: Sat, 9 Sep 2023 22:54:11 +0200 Subject: [PATCH] Fix potential memory leak due to not calling imagedestroy on GdImage objects --- app/Services/InstanceService.php | 3 +++ app/Util/Media/Blurhash.php | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Services/InstanceService.php b/app/Services/InstanceService.php index 1cead8d48..2ad991063 100644 --- a/app/Services/InstanceService.php +++ b/app/Services/InstanceService.php @@ -120,6 +120,9 @@ class InstanceService $pixels[] = $row; } + // Free the allocated GdImage object from memory: + imagedestroy($image); + $components_x = 4; $components_y = 4; $blurhash = Blurhash::encode($pixels, $components_x, $components_y); diff --git a/app/Util/Media/Blurhash.php b/app/Util/Media/Blurhash.php index c0cca59b9..8e232ea17 100644 --- a/app/Util/Media/Blurhash.php +++ b/app/Util/Media/Blurhash.php @@ -44,6 +44,9 @@ class Blurhash { $pixels[] = $row; } + // Free the allocated GdImage object from memory: + imagedestroy($image); + $components_x = 4; $components_y = 4; $blurhash = BlurhashEngine::encode($pixels, $components_x, $components_y); @@ -53,4 +56,4 @@ class Blurhash { return $blurhash; } -} \ No newline at end of file +}