From: Sara Golemon Date: Fri, 27 Jun 2003 01:46:30 +0000 (+0000) Subject: MFH: Plug memory leaks when freeing contexts (particularly options) X-Git-Tag: php-4.3.3RC2~240 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5d8e11306a8cc8f5592ddf936b6b753600fa54c;p=php MFH: Plug memory leaks when freeing contexts (particularly options) --- diff --git a/ext/standard/file.c b/ext/standard/file.c index c77aaa0018..232008ffcc 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -134,7 +134,12 @@ PHPAPI int php_le_stream_context(void) static ZEND_RSRC_DTOR_FUNC(file_context_dtor) { - php_stream_context_free((php_stream_context*)rsrc->ptr); + php_stream_context *context = (php_stream_context*)rsrc->ptr; + if (context->options) { + zval_ptr_dtor(&context->options); + context->options = NULL; + } + php_stream_context_free(context); } static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC) @@ -888,7 +893,6 @@ static int parse_context_options(php_stream_context *context, zval *options) while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(wval), (void**)&oval, &opos)) { if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(wval), &okey, &okey_len, &num_key, 0, &opos)) { - ZVAL_ADDREF(*oval); php_stream_context_set_option(context, wkey, okey, *oval); } zend_hash_move_forward_ex(Z_ARRVAL_PP(wval), &opos); diff --git a/main/streams.c b/main/streams.c index 3d3c42cee2..be017d280c 100755 --- a/main/streams.c +++ b/main/streams.c @@ -2819,7 +2819,10 @@ PHPAPI void php_stream_notification_notify(php_stream_context *context, int noti PHPAPI void php_stream_context_free(php_stream_context *context) { - zval_ptr_dtor(&context->options); + if (context->options) { + zval_ptr_dtor(&context->options); + context->options = NULL; + } efree(context); }