mirror of
https://github.com/php/php-src.git
synced 2024-12-01 05:43:38 +08:00
MFB
Plug leak in context notifiers, implement notifier->dtor
This commit is contained in:
parent
ecf58cf895
commit
2e4ef86e10
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user