summaryrefslogtreecommitdiff
path: root/main/streams/streams.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2003-05-21 13:33:55 +0000
committerWez Furlong <wez@php.net>2003-05-21 13:33:55 +0000
commit2d1a6e5dc23ace4583ee2e6f8b55c1ef21f06803 (patch)
tree3fa144f26bfba2b16d9df6dc84fb782676db705e /main/streams/streams.c
parent654f141e1cb17914652a03355b7899f89712756c (diff)
downloadphp-git-2d1a6e5dc23ace4583ee2e6f8b55c1ef21f06803.tar.gz
MFB context refcounting and text-mode fopen fixes
Diffstat (limited to 'main/streams/streams.c')
-rwxr-xr-xmain/streams/streams.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 5d6ef4fc21..b0ddf37de6 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -53,6 +53,14 @@ PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash()
return &url_stream_wrappers_hash;
}
+static int _php_stream_release_context(list_entry *le, void *pContext TSRMLS_DC)
+{
+ if (le->ptr == pContext) {
+ return --le->refcount == 0;
+ }
+ return 0;
+}
+
static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
php_stream *stream;
@@ -69,6 +77,13 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream);
stream->rsrc_id = FAILURE;
+ if (stream->context) {
+ zend_hash_apply_with_argument(&EG(regular_list),
+ (apply_func_arg_t) _php_stream_release_context,
+ stream->context TSRMLS_CC);
+ stream->context = NULL;
+ }
+
return 0;
}
@@ -1643,8 +1658,12 @@ PHPAPI int php_stream_context_set_option(php_stream_context *context,
const char *wrappername, const char *optionname, zval *optionvalue)
{
zval **wrapperhash;
- zval *category;
+ zval *category, *copied_val;
+ ALLOC_INIT_ZVAL(copied_val);
+ *copied_val = *optionvalue;
+ zval_copy_ctor(copied_val);
+
if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) {
MAKE_STD_ZVAL(category);
@@ -1656,7 +1675,7 @@ PHPAPI int php_stream_context_set_option(php_stream_context *context,
ZVAL_ADDREF(optionvalue);
wrapperhash = &category;
}
- return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&optionvalue, sizeof(zval *), NULL);
+ return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL);
}
/* }}} */