]> granicus.if.org Git - php/commitdiff
MFH: Plug memory leaks when freeing contexts (particularly options)
authorSara Golemon <pollita@php.net>
Fri, 27 Jun 2003 01:46:30 +0000 (01:46 +0000)
committerSara Golemon <pollita@php.net>
Fri, 27 Jun 2003 01:46:30 +0000 (01:46 +0000)
ext/standard/file.c
main/streams.c

index c77aaa00187d25599cfd314ed403f4fe4241c893..232008ffcce277d3658ac1e0f0122039584acaef 100644 (file)
@@ -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);
index 3d3c42cee253bdaa65662a0efb4b01800251d619..be017d280c2834b81bfbe63009a35305602f23a4 100755 (executable)
@@ -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);
 }