Skip to content

Commit a18ad19

Browse files
committed
Fixed bug #78396
1 parent f465560 commit a18ad19

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.4.0beta3
44

5+
- Core:
6+
. Fixed bug #78396 (Second file_put_contents in Shutdown hangs script).
7+
(Nikita)
8+
59
- Date:
610
. Fixed bug #78383 (Casting a DateTime to array no longer returns its
711
properties). (Nikita)

Zend/tests/bug78396.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #78396: Second file_put_contents in Shutdown hangs script
3+
--FILE--
4+
<?php
5+
6+
register_shutdown_function(function () {
7+
file_put_contents(__DIR__ . '/bug78396.txt', '1', FILE_APPEND | LOCK_EX);
8+
file_put_contents(__DIR__ . '/bug78396.txt', '2', FILE_APPEND | LOCK_EX);
9+
echo "Done\n";
10+
});
11+
12+
?>
13+
--CLEAN--
14+
<?php
15+
unlink(__DIR__ . '/bug78396.txt');
16+
?>
17+
--EXPECT--
18+
Done

Zend/zend_execute_API.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ void shutdown_executor(void) /* {{{ */
265265
zend_llist_destroy(&CG(open_files));
266266
} zend_end_try();
267267

268+
EG(flags) |= EG_FLAGS_IN_RESOURCE_SHUTDOWN;
268269
zend_try {
269270
zend_close_rsrc_list(&EG(regular_list));
270271
} zend_end_try();

Zend/zend_globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ struct _zend_executor_globals {
244244
#define EG_FLAGS_INITIAL (0)
245245
#define EG_FLAGS_IN_SHUTDOWN (1<<0)
246246
#define EG_FLAGS_OBJECT_STORE_NO_REUSE (1<<1)
247+
#define EG_FLAGS_IN_RESOURCE_SHUTDOWN (1<<2)
247248

248249
struct _zend_ini_scanner_globals {
249250
zend_file_handle *yy_in;

main/streams/streams.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options) /* {{{ */
370370
* stream free operations in shutdown unless they come from the resource list destruction,
371371
* or by freeing an enclosed stream (in which case resource list destruction will not have
372372
* freed it). */
373-
if ((EG(flags) & EG_FLAGS_IN_SHUTDOWN) &&
373+
if ((EG(flags) & EG_FLAGS_IN_RESOURCE_SHUTDOWN) &&
374374
!(close_options & (PHP_STREAM_FREE_RSRC_DTOR|PHP_STREAM_FREE_IGNORE_ENCLOSING))) {
375375
return 1;
376376
}

0 commit comments

Comments
 (0)