Index: main/php_streams.h =================================================================== RCS file: /repository/php-src/main/php_streams.h,v retrieving revision 1.103.2.1.2.1 diff -u -p -d -r1.103.2.1.2.1 php_streams.h --- main/php_streams.h 1 Jan 2007 09:36:11 -0000 1.103.2.1.2.1 +++ main/php_streams.h 20 Feb 2007 22:15:56 -0000 @@ -178,6 +178,8 @@ struct _php_stream_wrapper { * might otherwise cause the read to block for much longer than * is strictly required. */ #define PHP_STREAM_FLAG_AVOID_BLOCKING 16 + +#define PHP_STREAM_FLAG_NO_CLOSE 32 struct _php_stream { php_stream_ops *ops; Index: main/streams/plain_wrapper.c =================================================================== RCS file: /repository/php-src/main/streams/plain_wrapper.c,v retrieving revision 1.52.2.6.2.15 diff -u -p -d -r1.52.2.6.2.15 plain_wrapper.c --- main/streams/plain_wrapper.c 13 Feb 2007 23:39:14 -0000 1.52.2.6.2.15 +++ main/streams/plain_wrapper.c 20 Feb 2007 22:15:57 -0000 @@ -392,16 +392,7 @@ static int php_stdiop_close(php_stream * data->file = NULL; } } else if (data->fd != -1) { -#if PHP_DEBUG - if ((data->fd == 1 || data->fd == 2) && 0 == strcmp(sapi_module.name, \"cli\")) { - /* don\'t close stdout or stderr in CLI in DEBUG mode, as we want to see any leaks */ - ret = 0; - } else { - ret = close(data->fd); - } -#else ret = close(data->fd); -#endif data->fd = -1; } else { return 0; /* everything should be closed already -> success */ Index: main/streams/streams.c =================================================================== RCS file: /repository/php-src/main/streams/streams.c,v retrieving revision 1.82.2.6.2.10 diff -u -p -d -r1.82.2.6.2.10 streams.c --- main/streams/streams.c 15 Jan 2007 17:07:07 -0000 1.82.2.6.2.10 +++ main/streams/streams.c 20 Feb 2007 22:15:57 -0000 @@ -279,6 +279,10 @@ PHPAPI int _php_stream_free(php_stream * int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; int release_cast = 1; + if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) { + preserve_handle = 1; + } + #if STREAM_DEBUG fprintf(stderr, \"stream_free: %s:%p[%s] in_free=%d opts=%08x\\n\", stream->ops->label, stream, stream->orig_path, stream->in_free, close_options); #endif Index: sapi/cli/php_cli.c =================================================================== RCS file: /repository/php-src/sapi/cli/php_cli.c,v retrieving revision 1.129.2.13.2.14 diff -u -p -d -r1.129.2.13.2.14 php_cli.c --- sapi/cli/php_cli.c 20 Feb 2007 19:20:41 -0000 1.129.2.13.2.14 +++ sapi/cli/php_cli.c 20 Feb 2007 22:15:57 -0000 @@ -476,6 +476,12 @@ static void cli_register_file_handles(TS s_out = php_stream_open_wrapper_ex(\"php://stdout\", \"wb\", 0, NULL, sc_out); s_err = php_stream_open_wrapper_ex(\"php://stderr\", \"wb\", 0, NULL, sc_err); +#if PHP_DEBUG + /* do not close stdout and stderr */ + s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE; + s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE; +#endif + if (s_in==NULL || s_out==NULL || s_err==NULL) { FREE_ZVAL(zin); FREE_ZVAL(zout);