@@ -526,7 +526,7 @@ 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 ;
@@ -536,19 +536,21 @@ static void cli_register_file_handles(bool no_close) /* {{{ */
536
536
s_out = php_stream_open_wrapper_ex ("php://stdout" , "wb" , 0 , NULL , sc_out );
537
537
s_err = php_stream_open_wrapper_ex ("php://stderr" , "wb" , 0 , NULL , sc_err );
538
538
539
+ /* Release stream resources, but don't free the underlying handles. Othewrise,
540
+ * extensions which write to stderr or company during mshutdown/gshutdown
541
+ * won't have the expected functionality.
542
+ */
543
+ if (s_in ) s_in -> flags |= PHP_STREAM_FLAG_NO_RSCR_DTOR_CLOSE ;
544
+ if (s_out ) s_out -> flags |= PHP_STREAM_FLAG_NO_RSCR_DTOR_CLOSE ;
545
+ if (s_err ) s_err -> flags |= PHP_STREAM_FLAG_NO_RSCR_DTOR_CLOSE ;
546
+
539
547
if (s_in == NULL || s_out == NULL || s_err == NULL ) {
540
548
if (s_in ) php_stream_close (s_in );
541
549
if (s_out ) php_stream_close (s_out );
542
550
if (s_err ) php_stream_close (s_err );
543
551
return ;
544
552
}
545
553
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
554
s_in_process = s_in ;
553
555
554
556
php_stream_to_zval (s_in , & ic .value );
@@ -567,7 +569,6 @@ static void cli_register_file_handles(bool no_close) /* {{{ */
567
569
ec .name = zend_string_init_interned ("STDERR" , sizeof ("STDERR" )- 1 , 0 );
568
570
zend_register_constant (& ec );
569
571
}
570
- /* }}} */
571
572
572
573
static const char * param_mode_conflict = "Either execute direct code, process stdin or use a file.\n" ;
573
574
@@ -954,7 +955,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
954
955
switch (behavior ) {
955
956
case PHP_MODE_STANDARD :
956
957
if (script_file ) {
957
- cli_register_file_handles (/* no_close */ PHP_DEBUG || num_repeats > 1 );
958
+ cli_register_file_handles ();
958
959
}
959
960
960
961
if (interactive ) {
@@ -990,7 +991,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
990
991
}
991
992
break ;
992
993
case PHP_MODE_CLI_DIRECT :
993
- cli_register_file_handles (/* no_close */ PHP_DEBUG || num_repeats > 1 );
994
+ cli_register_file_handles ();
994
995
zend_eval_string_ex (exec_direct , NULL , "Command line code" , 1 );
995
996
break ;
996
997
@@ -1005,7 +1006,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
1005
1006
file_handle .filename = NULL ;
1006
1007
}
1007
1008
1008
- cli_register_file_handles (/* no_close */ PHP_DEBUG || num_repeats > 1 );
1009
+ cli_register_file_handles ();
1009
1010
1010
1011
if (exec_begin ) {
1011
1012
zend_eval_string_ex (exec_begin , NULL , "Command line begin code" , 1 );
0 commit comments