@@ -526,15 +526,21 @@ static void php_cli_usage(char *argv0)
526
526
527
527
static php_stream * s_in_process = NULL ;
528
528
529
- static void cli_register_file_handles (bool no_close ) /* {{{ */
529
+ static void cli_register_file_handles (void ) /* {{{ */
530
530
{
531
531
php_stream * s_in , * s_out , * s_err ;
532
532
php_stream_context * sc_in = NULL , * sc_out = NULL , * sc_err = NULL ;
533
533
zend_constant ic , oc , ec ;
534
534
535
- s_in = php_stream_open_wrapper_ex ("php://stdin" , "rb" , 0 , NULL , sc_in );
536
- s_out = php_stream_open_wrapper_ex ("php://stdout" , "wb" , 0 , NULL , sc_out );
537
- s_err = php_stream_open_wrapper_ex ("php://stderr" , "wb" , 0 , NULL , sc_err );
535
+ /* Release stream resources, but don't free the underlying handles. Othewrise,
536
+ * extensions which write to stderr or company during mshutdown/gshutdown
537
+ * won't have the expected functionality.
538
+ */
539
+ int options = PHP_STREAM_FLAG_NO_CLOSE ;
540
+
541
+ s_in = php_stream_open_wrapper_ex ("php://stdin" , "rb" , options , NULL , sc_in );
542
+ s_out = php_stream_open_wrapper_ex ("php://stdout" , "wb" , options , NULL , sc_out );
543
+ s_err = php_stream_open_wrapper_ex ("php://stderr" , "wb" , options , NULL , sc_err );
538
544
539
545
if (s_in == NULL || s_out == NULL || s_err == NULL ) {
540
546
if (s_in ) php_stream_close (s_in );
@@ -543,12 +549,6 @@ static void cli_register_file_handles(bool no_close) /* {{{ */
543
549
return ;
544
550
}
545
551
546
- if (no_close ) {
547
- s_in -> flags |= PHP_STREAM_FLAG_NO_CLOSE ;
548
- s_out -> flags |= PHP_STREAM_FLAG_NO_CLOSE ;
549
- s_err -> flags |= PHP_STREAM_FLAG_NO_CLOSE ;
550
- }
551
-
552
552
s_in_process = s_in ;
553
553
554
554
php_stream_to_zval (s_in , & ic .value );
@@ -954,7 +954,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
954
954
switch (behavior ) {
955
955
case PHP_MODE_STANDARD :
956
956
if (script_file ) {
957
- cli_register_file_handles (/* no_close */ PHP_DEBUG || num_repeats > 1 );
957
+ cli_register_file_handles ();
958
958
}
959
959
960
960
if (interactive ) {
@@ -989,7 +989,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
989
989
}
990
990
break ;
991
991
case PHP_MODE_CLI_DIRECT :
992
- cli_register_file_handles (/* no_close */ PHP_DEBUG || num_repeats > 1 );
992
+ cli_register_file_handles ();
993
993
zend_eval_string_ex (exec_direct , NULL , "Command line code" , 1 );
994
994
break ;
995
995
@@ -1004,7 +1004,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
1004
1004
file_handle .filename = NULL ;
1005
1005
}
1006
1006
1007
- cli_register_file_handles (/* no_close */ PHP_DEBUG || num_repeats > 1 );
1007
+ cli_register_file_handles ();
1008
1008
1009
1009
if (exec_begin ) {
1010
1010
zend_eval_string_ex (exec_begin , NULL , "Command line begin code" , 1 );
0 commit comments