tony2001 Wed Aug 6 09:03:37 2008 UTC
Modified files:
/php-src/main/streams streams.c
Log:
increase context refcount before open() to avoid crash when open() fails and
destroys the context
http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.167&r2=1.168&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.167
php-src/main/streams/streams.c:1.168
--- php-src/main/streams/streams.c:1.167 Fri Jul 11 12:40:20 2008
+++ php-src/main/streams/streams.c Wed Aug 6 09:03:36 2008
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.167 2008/07/11 12:40:20 tony2001 Exp $ */
+/* $Id: streams.c,v 1.168 2008/08/06 09:03:36 tony2001 Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -2414,14 +2414,22 @@
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);
- }
- /* increase context refcount only if the context is really used
*/
- if (stream && stream->context) {
- zend_list_addref(stream->context->rsrc_id);
+ /* 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
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php