Skip to content

Commit 51ed4a8

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
2 parents 4b081c2 + 61eebb5 commit 51ed4a8

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Zend/tests/object_gc_in_shutdown.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug object gc not working in shutdown
3+
--FILE--
4+
<?php
5+
ini_set('memory_limit', '2M');
6+
register_shutdown_function(function () {
7+
for ($n = 1000 * 1000; $n--;) {
8+
new stdClass;
9+
}
10+
echo "OK\n";
11+
});
12+
?>
13+
--EXPECT--
14+
OK

Zend/zend_globals.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ struct _zend_executor_globals {
234234
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
235235
};
236236

237-
#define EG_FLAGS_INITIAL 0x00
238-
#define EG_FLAGS_IN_SHUTDOWN 0x01
237+
#define EG_FLAGS_INITIAL (0)
238+
#define EG_FLAGS_IN_SHUTDOWN (1<<0)
239+
#define EG_FLAGS_OBJECT_STORE_NO_REUSE (1<<1)
239240

240241
struct _zend_ini_scanner_globals {
241242
zend_file_handle *yy_in;

Zend/zend_objects_API.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_destroy(zend_objects_store *objec
4141

4242
ZEND_API void ZEND_FASTCALL zend_objects_store_call_destructors(zend_objects_store *objects)
4343
{
44+
EG(flags) |= EG_FLAGS_OBJECT_STORE_NO_REUSE;
4445
if (objects->top > 1) {
4546
uint32_t i;
4647
for (i = 1; i < objects->top; i++) {
@@ -140,10 +141,10 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_put(zend_object *object)
140141
{
141142
int handle;
142143

143-
/* When in shutdown sequesnce - do not reuse previously freed handles, to make sure
144+
/* When in shutdown sequence - do not reuse previously freed handles, to make sure
144145
* the dtors for newly created objects are called in zend_objects_store_call_destructors() loop
145146
*/
146-
if (EG(objects_store).free_list_head != -1 && EXPECTED(!(EG(flags) & EG_FLAGS_IN_SHUTDOWN))) {
147+
if (EG(objects_store).free_list_head != -1 && EXPECTED(!(EG(flags) & EG_FLAGS_OBJECT_STORE_NO_REUSE))) {
147148
handle = EG(objects_store).free_list_head;
148149
EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]);
149150
} else if (UNEXPECTED(EG(objects_store).top == EG(objects_store).size)) {

0 commit comments

Comments
 (0)