Skip to content

Commit

Permalink
Corrected function names to module standard. Free callback structures…
Browse files Browse the repository at this point in the history
… recursively.
  • Loading branch information
Danack committed May 9, 2014
1 parent 8221be4 commit 2bb7e99
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
8 changes: 7 additions & 1 deletion imagick.c
Expand Up @@ -2922,7 +2922,13 @@ PHP_RINIT_FUNCTION(imagick)

PHP_RSHUTDOWN_FUNCTION(imagick)
{
cleanupProgressCallback(TSRMLS_C);
php_imagick_callback* progress_callback = IMAGICK_G(progress_callback);

if (progress_callback) {
php_imagick_cleanup_progress_callback(progress_callback TSRMLS_CC);
efree(progress_callback);
IMAGICK_G(progress_callback) = NULL;
}

#if defined(ZTS) && defined(PHP_WIN32)
/* We have the lock so lets release it */
Expand Down
8 changes: 4 additions & 4 deletions imagick_class.c
Expand Up @@ -10768,13 +10768,13 @@ PHP_METHOD(imagick, setprogressmonitor)
}
efree(cbname);

if (IMAGICK_G(progress_callback) != NULL) {
cleanupProgressCallback(TSRMLS_C);
}

php_imagick_callback *callback = (php_imagick_callback *) emalloc(sizeof(php_imagick_callback));

TSRMLS_SET_CTX(callback->thread_ctx);
//We can't free the previous callback as we can't guarantee that
//ImageMagick won't use it at some point. There is no 'unbind' function
//for previously set 'MagickSetImageProgressMonitor'
callback->previous_callback = IMAGICK_G(progress_callback);

ALLOC_ZVAL(callback->user_callback);
MAKE_COPY_ZVAL(&user_callback, callback->user_callback);
Expand Down
13 changes: 6 additions & 7 deletions imagick_helpers.c
Expand Up @@ -47,13 +47,15 @@ MagickBooleanType php_imagick_progress_monitor(const char *text, const MagickOff
return MagickTrue;
}

void cleanupProgressCallback(TSRMLS_D) {
php_imagick_callback* progress_callback = IMAGICK_G(progress_callback);
void php_imagick_cleanup_progress_callback(php_imagick_callback* progress_callback TSRMLS_DC) {

if (progress_callback) {
if (progress_callback->previous_callback) {
php_imagick_cleanup_progress_callback(progress_callback->previous_callback TSRMLS_CC);
efree(progress_callback->previous_callback);
}

zval_ptr_dtor(&progress_callback->user_callback);
efree(progress_callback);
IMAGICK_G(progress_callback) = NULL;
}
}

Expand Down Expand Up @@ -102,9 +104,6 @@ MagickBooleanType php_imagick_progress_monitor_callable(const char *text, const
zval_ptr_dtor(zargs[0]);
zval_ptr_dtor(zargs[1]);

efree(zargs[0]);
efree(zargs[1]);

if (retval_ptr) {
if (Z_TYPE_P(retval_ptr) == IS_BOOL) {
if (Z_LVAL_P(retval_ptr) == 0) {
Expand Down
1 change: 1 addition & 0 deletions php_imagick_defs.h
Expand Up @@ -46,6 +46,7 @@
typedef struct _php_imagick_callback {
void ***thread_ctx;
zval *user_callback;
struct _php_imagick_callback *previous_callback;
} php_imagick_callback;

/* Globals, needed for the ini settings */
Expand Down
2 changes: 1 addition & 1 deletion php_imagick_helpers.h
Expand Up @@ -36,7 +36,7 @@ unsigned char *php_imagick_zval_to_char_array(zval *param_array, long *num_eleme

MagickBooleanType php_imagick_progress_monitor(const char *text, const MagickOffsetType offset, const MagickSizeType span, void *client_data);

void cleanupProgressCallback(TSRMLS_D);
void php_imagick_cleanup_progress_callback(php_imagick_callback* progress_callback TSRMLS_DC);

MagickBooleanType php_imagick_progress_monitor_callable(const char *text, const MagickOffsetType offset, const MagickSizeType span, void *client_data);

Expand Down

0 comments on commit 2bb7e99

Please sign in to comment.