Skip to content

Commit

Permalink
Increment refcounts in mutable data copies
Browse files Browse the repository at this point in the history
For mutable_data on preloaded classes, there may be refcounted
values in the constants/properties table.
  • Loading branch information
nikic committed Jul 27, 2021
1 parent ccb6642 commit 8675380
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,7 @@ ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_
memcpy(new_c, c, sizeof(zend_class_constant));
c = new_c;
}
Z_TRY_ADDREF(c->value);
_zend_hash_append_ptr(constants_table, key, c);
} ZEND_HASH_FOREACH_END();

Expand Down Expand Up @@ -1437,7 +1438,7 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type) /
dst = default_properties_table;
end = dst + class_type->default_properties_count;
do {
ZVAL_COPY_VALUE_PROP(dst, src);
ZVAL_COPY_PROP(dst, src);
src++;
dst++;
} while (dst != end);
Expand Down
5 changes: 5 additions & 0 deletions ext/opcache/tests/preload_enum.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ enum MyEnum {
case Bar;
}
var_dump(MyEnum::Bar);

class Test {
public $x = MyEnum::Bar;
}
new Test;

0 comments on commit 8675380

Please sign in to comment.