summaryrefslogtreecommitdiff
path: root/main/streams/streams.c
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2009-11-15 20:30:57 +0000
committerFelipe Pena <felipe@php.net>2009-11-15 20:30:57 +0000
commitd3849fc38c9f75ada6704a6f4240fce3c2a44c7b (patch)
treec75be602f04df4bbfce5d6e71ea5c39b39da90a6 /main/streams/streams.c
parent21b7fb5f6de34f0dc83799a1cc05e83d553a9c5d (diff)
downloadphp-git-d3849fc38c9f75ada6704a6f4240fce3c2a44c7b.tar.gz
- Fixed bug #49936 (crash with ftp stream in php_stream_context_get_option())
(patch by Pierrick)
Diffstat (limited to 'main/streams/streams.c')
-rwxr-xr-xmain/streams/streams.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c
index ca628a16f6..5990d79b0c 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -2422,22 +2422,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC,
"wrapper does not support stream open");
} else {
- /* refcount++ to make sure the context doesn't get destroyed
- * if open() fails and stream is closed */
- if (context) {
- zend_list_addref(context->rsrc_id);
- }
-
stream = wrapper->wops->stream_opener(wrapper,
path_to_open, implicit_mode, options ^ REPORT_ERRORS,
opened_path, context STREAMS_REL_CC TSRMLS_CC);
-
- /* if open() succeeded and context was not used, do refcount--
- * XXX if a wrapper didn't actually use context (no way to know that)
- * and open() failed, refcount will stay increased */
- if (context && stream && !stream->context) {
- zend_list_delete(context->rsrc_id);
- }
}
/* if the caller asked for a persistent stream but the wrapper did not
@@ -2595,10 +2582,19 @@ PHPAPI php_stream *_php_stream_u_open_wrapper(zend_uchar type, zstr path, int pa
/* }}} */
/* {{{ context API */
-PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context)
+PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context TSRMLS_DC)
{
php_stream_context *oldcontext = stream->context;
+
stream->context = context;
+
+ if (context) {
+ zend_list_addref(context->rsrc_id);
+ }
+ if (oldcontext) {
+ zend_list_delete(oldcontext->rsrc_id);
+ }
+
return oldcontext;
}