com php-src: Don't disable object slot reuse while running shutdown functions: Zend/tests/object_gc_in_shutdown.phpt Zend /zend_globals.h
Zend/zend_objects_API.c

From: Date: Mon, 18 Mar 2019 09:02:31 +0000
Subject: com php-src: Don't disable object slot reuse while running shutdown functions: Zend/tests/object_gc_in_shutdown.phpt Zend /zend_globals.h
Zend/zend_objects_API.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-105189@lists.php.net to get a copy of this message
Commit: bd6eabd6591ae5a7c9ad75dfbe7cc575fa907eac Author: twosee <twose@qq.com> Sat, 16 Mar 2019 13:21:48 +0800 Committer: Nikita Popov <nikita.ppv@gmail.com> Mon, 18 Mar 2019 10:02:31 +0100 Parents: ab07bc1fff27c19b390e0f57ceb4a0523085fdfa Branches: PHP-7.2 PHP-7.3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bd6eabd6591ae5a7c9ad75dfbe7cc575fa907eac Log: Don't disable object slot reuse while running shutdown functions We only need to do this once we're running destructors. The current approach interferes with some event loop code that runs everything inside a shutdown function. Changed paths: A Zend/tests/object_gc_in_shutdown.phpt M Zend/zend_globals.h M Zend/zend_objects_API.c Diff: diff --git a/Zend/tests/object_gc_in_shutdown.phpt b/Zend/tests/object_gc_in_shutdown.phpt new file mode 100644 index 0000000..d55c08d --- /dev/null +++ b/Zend/tests/object_gc_in_shutdown.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug object gc not working in shutdown +--FILE-- +<?php +ini_set('memory_limit', '2M'); +register_shutdown_function(function () { + for ($n = 1000 * 1000; $n--;) { + new stdClass; + } + echo "OK\n"; +}); +?> +--EXPECT-- +OK diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index 802c7be..dae93d9 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -230,8 +230,9 @@ struct _zend_executor_globals { void *reserved[ZEND_MAX_RESERVED_RESOURCES]; }; -#define EG_FLAGS_INITIAL 0x00 -#define EG_FLAGS_IN_SHUTDOWN 0x01 +#define EG_FLAGS_INITIAL (0) +#define EG_FLAGS_IN_SHUTDOWN (1<<0) +#define EG_FLAGS_OBJECT_STORE_NO_REUSE (1<<1) struct _zend_ini_scanner_globals { zend_file_handle *yy_in; diff --git a/Zend/zend_objects_API.c b/Zend/zend_objects_API.c index 2cb496d..3e3c8a8 100644 --- a/Zend/zend_objects_API.c +++ b/Zend/zend_objects_API.c @@ -43,6 +43,7 @@ ZEND_API void zend_objects_store_destroy(zend_objects_store *objects) ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects) { + EG(flags) |= EG_FLAGS_OBJECT_STORE_NO_REUSE; if (objects->top > 1) { uint32_t i; for (i = 1; i < objects->top; i++) { @@ -133,10 +134,10 @@ ZEND_API void zend_objects_store_put(zend_object *object) { int handle; - /* When in shutdown sequesnce - do not reuse previously freed handles, to make sure + /* When in shutdown sequence - do not reuse previously freed handles, to make sure * the dtors for newly created objects are called in zend_objects_store_call_destructors() loop */ - if (!(EG(flags) & EG_FLAGS_IN_SHUTDOWN) && EG(objects_store).free_list_head != -1) { + if (EG(objects_store).free_list_head != -1 && EXPECTED(!(EG(flags) & EG_FLAGS_OBJECT_STORE_NO_REUSE))) { handle = EG(objects_store).free_list_head; EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]); } else {

« previous php.cvs (#105189) next »