]> granicus.if.org Git - php/commitdiff
Plug leak (context options not freed)
authorSara Golemon <pollita@php.net>
Fri, 13 Jun 2003 21:33:59 +0000 (21:33 +0000)
committerSara Golemon <pollita@php.net>
Fri, 13 Jun 2003 21:33:59 +0000 (21:33 +0000)
Make contexts auto-registered, ensures userland contexts
and C API contexts are both dealt with on request shutdown.
Also brings contexts in keeping with streams which are already
auto-registered.

ext/standard/basic_functions.c
ext/standard/file.c
ext/standard/streamsfuncs.c
main/streams/php_stream_context.h
main/streams/streams.c

index 123f6b04b5aa4aec053bbc23ed01dd625e5c3d66..920fc9ed26a298b5e91a0d38a35ae1f840f338cb 100644 (file)
@@ -1247,11 +1247,6 @@ PHP_RSHUTDOWN_FUNCTION(basic)
                BG(user_filter_map) = NULL;
        }
 
-       /* cleanup any default context that was created */
-       if (FG(default_context)) {
-               php_stream_context_free(FG(default_context));
-       }
-       
        return SUCCESS;
 }
 
index 1d1429476c92221ed6caf23e265ee8b737722e12..7e89e3b8e4e871b245bb4ec87d97b6764e80a625 100644 (file)
@@ -129,7 +129,9 @@ 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;
+       zval_dtor(context->options);
+       php_stream_context_free(context);
 }
 
 static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC)
index 4c65489357bf6fdcc47290128c5b1d86698e7f85..8a2c01cc351a176d270d37d7ce4b01fb0be66661 100644 (file)
@@ -802,7 +802,7 @@ PHP_FUNCTION(stream_context_create)
                parse_context_options(context, params);
        }
        
-       ZEND_REGISTER_RESOURCE(return_value, context, php_le_stream_context());
+       php_stream_context_to_zval(context, return_value);
 }
 /* }}} */
 
index 02aff9e862ed3a27f8f97eca1e829886408cb759..488029938b82b1e1a1b986d41d13db076709cab1 100644 (file)
@@ -38,6 +38,8 @@ typedef void (*php_stream_notification_func)(php_stream_context *context,
                FG(default_context) ? FG(default_context) : \
                (FG(default_context) = php_stream_context_alloc()) )
 
+#define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); }
+
 typedef struct _php_stream_notifier {
        php_stream_notification_func func;
        void *ptr;
@@ -48,6 +50,7 @@ typedef struct _php_stream_notifier {
 struct _php_stream_context {
        php_stream_notifier *notifier;
        zval *options;  /* hash keyed by wrapper family or specific wrapper */
+       int rsrc_id;    /* used for auto-cleanup */
 };
 
 PHPAPI void php_stream_context_free(php_stream_context *context);
index d3e3968cbd3fb869530d4a8e85d73281bb7d5b93..b396a260b22df52a1102b59ca0fea00902f83752 100755 (executable)
@@ -1630,6 +1630,7 @@ PHPAPI php_stream_context *php_stream_context_alloc(void)
        MAKE_STD_ZVAL(context->options);
        array_init(context->options);
 
+       context->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context());
        return context;
 }