tony2001 Wed Aug 6 09:03:48 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/main/streams streams.c
Log:
MFH: 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.82.2.6.2.18.2.12&r2=1.82.2.6.2.18.2.13&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.82.2.6.2.18.2.12
php-src/main/streams/streams.c:1.82.2.6.2.18.2.13
--- php-src/main/streams/streams.c:1.82.2.6.2.18.2.12 Fri Jul 11 12:40:28 2008
+++ php-src/main/streams/streams.c Wed Aug 6 09:03:48 2008
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.82.2.6.2.18.2.12 2008/07/11 12:40:28 tony2001 Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.18.2.13 2008/08/06 09:03:48 tony2001 Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -1801,14 +1801,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, 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