Skip to content

Commit b9ff359

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Add missing zend_string_release_ex(tmp, 0) and cleanup
2 parents 4eaba3e + 37ac707 commit b9ff359

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

Zend/zend_execute.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
16771677
s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
16781678
ZSTR_H(s) = ZSTR_H(Z_STR_P(str));
16791679
if (Z_REFCOUNTED_P(str)) {
1680-
zend_string_release_ex(Z_STR_P(str), 0);
1680+
GC_DELREF(Z_STR_P(str));
16811681
}
16821682
ZVAL_NEW_STR(str, s);
16831683
}
@@ -1689,7 +1689,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
16891689
* Temporarily increase the refcount to detect this situation. */
16901690
GC_ADDREF(s);
16911691
offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC);
1692-
if (GC_DELREF(s) == 0) {
1692+
if (UNEXPECTED(GC_DELREF(s) == 0)) {
16931693
zend_string_efree(s);
16941694
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
16951695
ZVAL_NULL(EX_VAR(opline->result.var));
@@ -1729,8 +1729,11 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
17291729
}
17301730
/* Convert to string, just the time to pick the 1st byte */
17311731
tmp = zval_try_get_string_func(value);
1732-
if (GC_DELREF(s) == 0) {
1732+
if (UNEXPECTED(GC_DELREF(s) == 0)) {
17331733
zend_string_efree(s);
1734+
if (tmp) {
1735+
zend_string_release_ex(tmp, 0);
1736+
}
17341737
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
17351738
ZVAL_NULL(EX_VAR(opline->result.var));
17361739
}
@@ -1765,7 +1768,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
17651768
* Temporarily increase the refcount to detect this situation. */
17661769
GC_ADDREF(s);
17671770
zend_error(E_WARNING, "Only the first byte will be assigned to the string offset");
1768-
if (GC_DELREF(s) == 0) {
1771+
if (UNEXPECTED(GC_DELREF(s) == 0)) {
17691772
zend_string_efree(s);
17701773
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
17711774
ZVAL_NULL(EX_VAR(opline->result.var));
@@ -2589,11 +2592,11 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
25892592
case IS_UNDEF:
25902593
/* The string may be destroyed while throwing the notice.
25912594
* Temporarily increase the refcount to detect this situation. */
2592-
if (!(GC_FLAGS(str) & IS_ARRAY_IMMUTABLE)) {
2595+
if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
25932596
GC_ADDREF(str);
25942597
}
25952598
ZVAL_UNDEFINED_OP2();
2596-
if (!(GC_FLAGS(str) & IS_ARRAY_IMMUTABLE) && GC_DELREF(str) == 0) {
2599+
if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) {
25972600
zend_string_efree(str);
25982601
ZVAL_NULL(result);
25992602
return;
@@ -2606,11 +2609,11 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
26062609
if (type != BP_VAR_IS) {
26072610
/* The string may be destroyed while throwing the notice.
26082611
* Temporarily increase the refcount to detect this situation. */
2609-
if (!(GC_FLAGS(str) & IS_ARRAY_IMMUTABLE)) {
2612+
if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
26102613
GC_ADDREF(str);
26112614
}
26122615
zend_error(E_WARNING, "String offset cast occurred");
2613-
if (!(GC_FLAGS(str) & IS_ARRAY_IMMUTABLE) && GC_DELREF(str) == 0) {
2616+
if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) {
26142617
zend_string_efree(str);
26152618
ZVAL_NULL(result);
26162619
return;

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
948948
s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
949949
ZSTR_H(s) = ZSTR_H(Z_STR_P(str));
950950
if (Z_REFCOUNTED_P(str)) {
951-
zend_string_release_ex(Z_STR_P(str), 0);
951+
GC_DELREF(Z_STR_P(str));
952952
}
953953
ZVAL_NEW_STR(str, s);
954954
}
@@ -958,7 +958,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
958958
* Temporarily increase the refcount to detect this situation. */
959959
GC_ADDREF(s);
960960
offset = zend_check_string_offset(dim/*, BP_VAR_W*/);
961-
if (GC_DELREF(s) == 0) {
961+
if (UNEXPECTED(GC_DELREF(s) == 0)) {
962962
zend_string_efree(s);
963963
if (result) {
964964
ZVAL_NULL(result);
@@ -1000,8 +1000,11 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
10001000
/* Convert to string, just the time to pick the 1st byte */
10011001
tmp = zval_try_get_string_func(value);
10021002

1003-
if (GC_DELREF(s) == 0) {
1003+
if (UNEXPECTED(GC_DELREF(s) == 0)) {
10041004
zend_string_efree(s);
1005+
if (tmp) {
1006+
zend_string_release_ex(tmp, 0);
1007+
}
10051008
if (result) {
10061009
ZVAL_NULL(result);
10071010
}
@@ -1044,7 +1047,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
10441047
* Temporarily increase the refcount to detect this situation. */
10451048
GC_ADDREF(s);
10461049
zend_error(E_WARNING, "Only the first byte will be assigned to the string offset");
1047-
if (GC_DELREF(s) == 0) {
1050+
if (UNEXPECTED(GC_DELREF(s) == 0)) {
10481051
zend_string_efree(s);
10491052
if (result) {
10501053
ZVAL_NULL(result);

0 commit comments

Comments
 (0)