Skip to content

Commit a370ceb

Browse files
author
Ilia Alshanetsky
committed
Fixed memory leak, when invalid context is specified.
1 parent cbfb63c commit a370ceb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ext/standard/streamsfuncs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,10 @@ static int parse_context_options(php_stream_context *context, zval *options)
669669

670670
static int parse_context_params(php_stream_context *context, zval *params)
671671
{
672-
int ret = SUCCESS;
672+
int ret = FAILURE;
673673
zval **tmp;
674674

675-
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "notification", sizeof("notification"), (void**)&tmp)) {
675+
if ((ret = zend_hash_find(Z_ARRVAL_P(params), "notification", sizeof("notification"), (void**)&tmp)) == SUCCESS) {
676676

677677
if (context->notifier) {
678678
php_stream_notification_free(context->notifier);
@@ -684,10 +684,14 @@ static int parse_context_params(php_stream_context *context, zval *params)
684684
context->notifier->ptr = *tmp;
685685
ZVAL_ADDREF(*tmp);
686686
}
687-
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "options", sizeof("options"), (void**)&tmp)) {
687+
if ((ret = zend_hash_find(Z_ARRVAL_P(params), "options", sizeof("options"), (void**)&tmp)) == SUCCESS) {
688688
parse_context_options(context, *tmp);
689689
}
690-
690+
691+
if (ret != SUCCESS) {
692+
php_stream_context_free(context);
693+
}
694+
691695
return ret;
692696
}
693697

0 commit comments

Comments
 (0)