Skip to content

Commit

Permalink
Release memory when replacing drawing wand
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Galanin committed Oct 16, 2023
1 parent bc72c29 commit 0ed26fd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions imagickdraw_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,23 +349,32 @@ PHP_METHOD(ImagickDraw, setResolution)
internd = Z_IMAGICKDRAW_P(getThis());

spprintf(&buf, 512, "%fx%f", x, y);

draw_info = PeekDrawingWand(internd->drawing_wand);
#if MagickLibVersion >= 0x693
d_wand = AcquireDrawingWand(draw_info, NULL);

if (!DrawSetDensity(d_wand, buf)) {
efree (buf);
php_imagick_throw_exception(IMAGICKDRAW_CLASS, "Failed to SetDensity" TSRMLS_CC);
RETURN_THROWS();
}
#else
density = AcquireString(buf);
efree (buf);

if (!density) {
efree (buf);
php_imagick_throw_exception(IMAGICKDRAW_CLASS, "Failed to allocate memory" TSRMLS_CC);
return;
RETURN_THROWS();
}

draw_info = PeekDrawingWand(internd->drawing_wand);
draw_info->density = density;

draw_info->density = density;

#if MagickLibVersion >= 0x693
d_wand = AcquireDrawingWand(draw_info, NULL);
#else
d_wand = (DrawingWand *) DrawAllocateWand(draw_info, NULL);
#endif
efree (buf);
draw_info=DestroyDrawInfo(draw_info);

if (!d_wand) {
php_imagick_throw_exception(IMAGICKDRAW_CLASS, "Failed to allocate new DrawingWand structure" TSRMLS_CC);
Expand Down

0 comments on commit 0ed26fd

Please sign in to comment.