[prev in list] [next in list] [prev in thread] [next in thread]
List: pecl-cvs
Subject: [PECL-CVS] =?utf-8?q?svn:_/pecl/imagick/trunk/_imagick=5Fclass.c_imagick=5Fhelpers.c_php=5Fimagick=5
From: Mikko_Koppanen <mkoppanen () php ! net>
Date: 2011-07-31 1:51:42
Message-ID: svn-mkoppanen-1312077102-313988-344865064 () svn ! php ! net
[Download RAW message or body]
mkoppanen Sun, 31 Jul 2011 01:51:42 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=313988
Log:
Fix potential memory leaks
Changed paths:
U pecl/imagick/trunk/imagick_class.c
U pecl/imagick/trunk/imagick_helpers.c
U pecl/imagick/trunk/php_imagick_helpers.h
Modified: pecl/imagick/trunk/imagick_class.c
===================================================================
--- pecl/imagick/trunk/imagick_class.c 2011-07-31 01:50:50 UTC (rev 313987)
+++ pecl/imagick/trunk/imagick_class.c 2011-07-31 01:51:42 UTC (rev 313988)
@@ -545,17 +545,22 @@
draw = (DrawingWand *)NewDrawingWand();
mask_image = (MagickWand *)NewMagickWand();
+#define exit_cleanup() \
+ if (color != NULL) color = DestroyPixelWand(color); \
+ if (draw != NULL) draw = DestroyDrawingWand(draw); \
+ if (mask_image != NULL) mask_image = DestroyMagickWand(mask_image);
+
status = PixelSetColor(color, "transparent");
if (status == MagickFalse) {
- deallocate_wands(mask_image, draw, color TSRMLS_CC);
+ exit_cleanup();
IMAGICK_THROW_EXCEPTION_WITH_MESSAGE(IMAGICK_CLASS, "Unable to set pixel color", 1);
}
status = MagickNewImage(mask_image, image_width, image_height, color);
if (status == MagickFalse) {
- deallocate_wands(mask_image, draw, color TSRMLS_CC);
+ exit_cleanup();
IMAGICK_THROW_EXCEPTION_WITH_MESSAGE(IMAGICK_CLASS, "Unable to allocate mask image", 1);
}
@@ -563,7 +568,7 @@
status = PixelSetColor(color, "white");
if (status == MagickFalse) {
- deallocate_wands(mask_image, draw, color TSRMLS_CC);
+ exit_cleanup();
IMAGICK_THROW_EXCEPTION_WITH_MESSAGE(IMAGICK_CLASS, "Unable to set pixel color", 1);
}
@@ -571,7 +576,7 @@
status = PixelSetColor(color, "black");
if (status == MagickFalse) {
- deallocate_wands(mask_image, draw, color TSRMLS_CC);
+ exit_cleanup();
IMAGICK_THROW_EXCEPTION_WITH_MESSAGE(IMAGICK_CLASS, "Unable to set pixel color", 1);
}
@@ -584,19 +589,20 @@
IMAGICK_RESTORE_LOCALE(old_locale, restore);
if (status == MagickFalse) {
- deallocate_wands(mask_image, draw, color TSRMLS_CC);
+ exit_cleanup();
IMAGICK_THROW_EXCEPTION_WITH_MESSAGE(IMAGICK_CLASS, "Unable to draw on image", 1);
}
status = MagickCompositeImage(intern->magick_wand, mask_image, DstInCompositeOp, 0, 0);
if (status == MagickFalse) {
- deallocate_wands(mask_image, draw, color TSRMLS_CC);
+ exit_cleanup();
IMAGICK_THROW_EXCEPTION_WITH_MESSAGE(IMAGICK_CLASS, "Unable to composite image", 1);
}
- deallocate_wands(mask_image, draw, color TSRMLS_CC);
+ exit_cleanup();
RETURN_TRUE;
+#undef exit_cleanup
}
/* }}} */
@@ -2319,7 +2325,7 @@
if (status == MagickFalse) {
IMAGICK_THROW_IMAGICK_EXCEPTION(intern->magick_wand, "Unable to transform image colorspace", 1);
}
- RETURN_TRUE;
+ RETURN_TRUE;
}
/* }}} */
#endif
@@ -5123,7 +5129,7 @@
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
return;
}
-
+
intern = (php_imagick_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
IMAGICK_CHECK_NOT_EMPTY(intern->magick_wand, 1, 1);
@@ -5135,6 +5141,7 @@
}
if (status == MagickFalse) {
+ tmp_wand = DestroyPixelWand(tmp_wand);
IMAGICK_THROW_IMAGICK_EXCEPTION(intern->magick_wand, "Unable to get image background color", 1);
}
@@ -5201,6 +5208,7 @@
}
if (status == MagickFalse) {
+ tmp_wand = DestroyPixelWand(tmp_wand);
IMAGICK_THROW_IMAGICK_EXCEPTION(intern->magick_wand, "Unable to get image border color", 1);
}
@@ -5397,6 +5405,7 @@
}
if (status == MagickFalse) {
+ tmp_wand = DestroyPixelWand(tmp_wand);
IMAGICK_THROW_IMAGICK_EXCEPTION(intern->magick_wand, "Unable to get image colormap color", 1);
}
@@ -5741,6 +5750,7 @@
}
if (status == MagickFalse) {
+ tmp_wand = DestroyPixelWand(tmp_wand);
IMAGICK_THROW_IMAGICK_EXCEPTION(intern->magick_wand, "Unable get image matter color", 1);
}
@@ -5813,7 +5823,7 @@
status = MagickGetImagePixelColor(intern->magick_wand, x, y , tmp_wand);
if (status == MagickFalse) {
- tmp_wand = DestroyPixelWand(tmp_wand);
+ tmp_wand = DestroyPixelWand(tmp_wand);
IMAGICK_THROW_IMAGICK_EXCEPTION(intern->magick_wand, "Unable get image pixel color", 1);
}
Modified: pecl/imagick/trunk/imagick_helpers.c
===================================================================
--- pecl/imagick/trunk/imagick_helpers.c 2011-07-31 01:50:50 UTC (rev 313987)
+++ pecl/imagick/trunk/imagick_helpers.c 2011-07-31 01:51:42 UTC (rev 313988)
@@ -391,21 +391,6 @@
return 1;
}
-void deallocate_wands(MagickWand *magick, DrawingWand *draw, PixelWand *pixel TSRMLS_DC)
-{
- if (magick != (MagickWand *)NULL) {
- magick = (MagickWand *)DestroyMagickWand(magick);
- }
-
- if (draw != (DrawingWand *)NULL) {
- draw = (DrawingWand *)DestroyDrawingWand(draw);
- }
-
- if (pixel != (PixelWand *)NULL) {
- pixel = (PixelWand *)DestroyPixelWand(pixel);
- }
-}
-
void *get_pointinfo_array(zval *coordinate_array, int *num_elements TSRMLS_DC)
{
PointInfo *coordinates;
Modified: pecl/imagick/trunk/php_imagick_helpers.h
===================================================================
--- pecl/imagick/trunk/php_imagick_helpers.h 2011-07-31 01:50:50 UTC (rev 313987)
+++ pecl/imagick/trunk/php_imagick_helpers.h 2011-07-31 01:51:42 UTC (rev 313988)
@@ -24,8 +24,6 @@
void add_assoc_string_helper(zval *retvalue, char *name, char *key, char *hash_value TSRMLS_DC);
-void deallocate_wands(MagickWand *magick, DrawingWand *draw, PixelWand *pixel TSRMLS_DC);
-
void *get_pointinfo_array(zval *coordinate_array, int *num_elements TSRMLS_DC);
#if MagickLibVersion <= 0x628
--
PECL CVS Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic