Plug leak in context notifiers, implement notifier->dtor
This commit is contained in:
Sara Golemon 2003-06-27 16:23:58 +00:00
parent ecf58cf895
commit 2e4ef86e10
3 changed files with 17 additions and 2 deletions

View File

@ -631,6 +631,14 @@ static void user_space_stream_notifier(php_stream_context *context, int notifyco
}
}
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;
@ -679,6 +687,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 (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "options", sizeof("options"), (void**)&tmp)) {
parse_context_options(context, *tmp);

View File

@ -40,12 +40,15 @@ typedef void (*php_stream_notification_func)(php_stream_context *context,
#define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); }
typedef struct _php_stream_notifier {
typedef struct _php_stream_notifier 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;

View File

@ -1649,6 +1649,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);
}