File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-18833 (Use after free with weakmaps dependent on destruction order)
3
+ --FILE--
4
+ <?php
5
+
6
+ class a {
7
+ public static WeakMap $ map ;
8
+ public static Generator $ storage ;
9
+ }
10
+
11
+ a::$ map = new WeakMap ;
12
+
13
+ $ closure = function () {
14
+ $ obj = new a ;
15
+ a::$ map [$ obj ] = true ;
16
+ yield $ obj ;
17
+ };
18
+ a::$ storage = $ closure ();
19
+ a::$ storage ->current ();
20
+
21
+ echo "ok \n" ;
22
+ ?>
23
+ --EXPECT--
24
+ ok
Original file line number Diff line number Diff line change @@ -100,7 +100,9 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_free_object_storage(zend_objects_
100
100
if (IS_OBJ_VALID (obj )) {
101
101
if (!(OBJ_FLAGS (obj ) & IS_OBJ_FREE_CALLED )) {
102
102
GC_ADD_FLAGS (obj , IS_OBJ_FREE_CALLED );
103
- if (obj -> handlers -> free_obj != zend_object_std_dtor ) {
103
+ if (obj -> handlers -> free_obj != zend_object_std_dtor
104
+ || (OBJ_FLAGS (obj ) & IS_OBJ_WEAKLY_REFERENCED )
105
+ ) {
104
106
GC_ADDREF (obj );
105
107
obj -> handlers -> free_obj (obj );
106
108
}
You can’t perform that action at this time.
0 commit comments