diff options
author | Sara Golemon <pollita@php.net> | 2003-06-13 21:33:59 +0000 |
---|---|---|
committer | Sara Golemon <pollita@php.net> | 2003-06-13 21:33:59 +0000 |
commit | 99db19661a60396aaebc91b75fbf474e1ebd9678 (patch) | |
tree | 5fe391bc5f551191e3becb1501c1443b5e973215 | |
parent | 785bc24a9b9f4206493759b5e9d71fde27630d54 (diff) | |
download | php-git-99db19661a60396aaebc91b75fbf474e1ebd9678.tar.gz |
Plug leak (context options not freed)
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.
-rw-r--r-- | ext/standard/basic_functions.c | 5 | ||||
-rw-r--r-- | ext/standard/file.c | 4 | ||||
-rw-r--r-- | ext/standard/streamsfuncs.c | 2 | ||||
-rw-r--r-- | main/streams/php_stream_context.h | 3 | ||||
-rwxr-xr-x | main/streams/streams.c | 1 |
5 files changed, 8 insertions, 7 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 123f6b04b5..920fc9ed26 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -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; } diff --git a/ext/standard/file.c b/ext/standard/file.c index 1d1429476c..7e89e3b8e4 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 4c65489357..8a2c01cc35 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -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); } /* }}} */ diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h index 02aff9e862..488029938b 100644 --- a/main/streams/php_stream_context.h +++ b/main/streams/php_stream_context.h @@ -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); diff --git a/main/streams/streams.c b/main/streams/streams.c index d3e3968cbd..b396a260b2 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -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; } |