From 97b55a966d2ab2ba4928ae00e57bcff954741bdd Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Fri, 27 Jun 2003 16:16:46 +0000 Subject: [PATCH] Plug the last (hopefully) of the PHP4 context leaks. This one regarding notifier->ptr --- ext/standard/file.c | 9 +++++++++ main/php_streams.h | 6 ++++-- main/streams.c | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index 232008ffcc..82c9c8b2f4 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -875,6 +875,14 @@ static void user_space_stream_notifier(php_stream_context *context, int notifyco zval_ptr_dtor(&retval); } +static void user_space_stream_notifier_dtor(php_stream_notifier *notifier) +{ + if (notifier && notifier->ptr) { + zval_ptr_dtor((zval **)&(notifier->ptr)); + notifier->ptr = NULL; + } +} + static int parse_context_options(php_stream_context *context, zval *options) { HashPosition pos, opos; @@ -923,6 +931,7 @@ static int parse_context_params(php_stream_context *context, zval *params) context->notifier->func = user_space_stream_notifier; context->notifier->ptr = *tmp; ZVAL_ADDREF(*tmp); + context->notifier->dtor = user_space_stream_notifier_dtor; } if ((ret = zend_hash_find(Z_ARRVAL_P(params), "options", sizeof("options"), (void**)&tmp)) == SUCCESS) { parse_context_options(context, *tmp); diff --git a/main/php_streams.h b/main/php_streams.h index 83e8c8b71c..ef65f592fe 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -96,6 +96,7 @@ typedef struct _php_stream php_stream; typedef struct _php_stream_wrapper php_stream_wrapper; typedef struct _php_stream_context php_stream_context; typedef struct _php_stream_filter php_stream_filter; +typedef struct _php_stream_notifier php_stream_notifier; /* callback for status notifications */ typedef void (*php_stream_notification_func)(php_stream_context *context, @@ -119,12 +120,13 @@ typedef struct _php_stream_dirent { #define PHP_STREAM_NOTIFIER_PROGRESS 1 -typedef struct _php_stream_notifier { +struct _php_stream_notifier { php_stream_notification_func func; + void (*dtor)(php_stream_notifier *notifier); void *ptr; int mask; size_t progress, progress_max; /* position for progress notification */ -} php_stream_notifier; +}; struct _php_stream_context { php_stream_notifier *notifier; diff --git a/main/streams.c b/main/streams.c index 8ea9f18a87..a549b59247 100755 --- a/main/streams.c +++ b/main/streams.c @@ -2849,6 +2849,9 @@ PHPAPI php_stream_notifier *php_stream_notification_alloc(void) PHPAPI void php_stream_notification_free(php_stream_notifier *notifier) { + if (notifier->dtor) { + notifier->dtor(notifier); + } efree(notifier); } -- 2.50.1