Skip to content

Commit 5474775

Browse files
author
Phil Wilkinson
committed
Fixed memory leak caused by loading GD images from string
1 parent 58ec68a commit 5474775

File tree

1 file changed

+3
-3
lines changed
  • src/PhpPresentation/Shape/Drawing

1 file changed

+3
-3
lines changed

src/PhpPresentation/Shape/Drawing/Gd.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,17 @@ public function __destruct()
301301
*/
302302
public function loadFromContent(string $content, string $fileName = '', string $prefix = 'PhpPresentationGd'): AbstractDrawingAdapter
303303
{
304+
// Check if the content is a valid image
304305
$image = @imagecreatefromstring($content);
305306
if ($image === false) {
306307
return $this;
307308
}
309+
// Clean up the image resource to avoid memory leaks
310+
@imagedestroy($image);
308311

309312
$tmpFile = tempnam(sys_get_temp_dir(), $prefix);
310313
file_put_contents($tmpFile, $content);
311314

312-
// Set image resource
313-
$this->setImageResource($image);
314-
315315
// Set path and mark as temporary for automatic cleanup
316316
$this->setPath($tmpFile);
317317
$this->setIsTemporaryFile(true);

0 commit comments

Comments
 (0)