Skip to content

Commit 5898583

Browse files
committed
Fixed some incorrect zval_dtor() usages
1 parent 3a8f260 commit 5898583

File tree

2 files changed

+144
-11
lines changed

2 files changed

+144
-11
lines changed

Zend/tests/gc_038.phpt

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
--TEST--
2+
GC 038: Garbage created by compound assignment operators (e.g. +=)
3+
--INI--
4+
zend.enable_gc = 1
5+
--FILE--
6+
<?php
7+
function test_add() {
8+
$x = new stdClass;
9+
$x->x= $x;
10+
@$x += 5;
11+
$n = gc_collect_cycles();
12+
echo "+=\t$n\n";
13+
}
14+
test_add();
15+
16+
function test_sub() {
17+
$x = new stdClass;
18+
$x->x= $x;
19+
@$x -= 5;
20+
$n = gc_collect_cycles();
21+
echo "-=\t$n\n";
22+
}
23+
test_sub();
24+
25+
function test_mul() {
26+
$x = new stdClass;
27+
$x->x= $x;
28+
@$x *= 5;
29+
$n = gc_collect_cycles();
30+
echo "*=\t$n\n";
31+
}
32+
test_mul();
33+
34+
function test_div() {
35+
$x = new stdClass;
36+
$x->x= $x;
37+
@$x /= 5;
38+
$n = gc_collect_cycles();
39+
echo "/=\t$n\n";
40+
}
41+
test_div();
42+
43+
function test_mod() {
44+
$x = new stdClass;
45+
$x->x= $x;
46+
@$x %= 5;
47+
$n = gc_collect_cycles();
48+
echo "%=\t$n\n";
49+
}
50+
test_mod();
51+
52+
function test_sl() {
53+
$x = new stdClass;
54+
$x->x= $x;
55+
@$x <<= 5;
56+
$n = gc_collect_cycles();
57+
echo "<<=\t$n\n";
58+
}
59+
test_sl();
60+
61+
function test_sr() {
62+
$x = new stdClass;
63+
$x->x= $x;
64+
@$x >>= 5;
65+
$n = gc_collect_cycles();
66+
echo ">>=\t$n\n";
67+
}
68+
test_sr();
69+
70+
function test_or() {
71+
$x = new stdClass;
72+
$x->x= $x;
73+
@$x |= 1;
74+
$n = gc_collect_cycles();
75+
echo "|=\t$n\n";
76+
}
77+
test_or();
78+
79+
function test_and() {
80+
$x = new stdClass;
81+
$x->x= $x;
82+
@$x &= 1;
83+
$n = gc_collect_cycles();
84+
echo "&=\t$n\n";
85+
}
86+
test_and();
87+
88+
function test_xor() {
89+
$x = new stdClass;
90+
$x->x= $x;
91+
@$x ^= 1;
92+
$n = gc_collect_cycles();
93+
echo "^=\t$n\n";
94+
}
95+
test_xor();
96+
97+
function test_pow() {
98+
$x = new stdClass;
99+
$x->x= $x;
100+
@$x **= 1;
101+
$n = gc_collect_cycles();
102+
echo "**=\t$n\n";
103+
}
104+
test_pow();
105+
106+
class Y {
107+
function __toString() {
108+
return "y";
109+
}
110+
}
111+
function test_concat() {
112+
$x = new Y;
113+
$x->x= $x;
114+
@$x .= "x";
115+
$n = gc_collect_cycles();
116+
echo ".=\t$n\n";
117+
}
118+
test_concat();
119+
?>
120+
--EXPECT--
121+
+= 1
122+
-= 1
123+
*= 1
124+
/= 1
125+
%= 1
126+
<<= 1
127+
>>= 1
128+
|= 1
129+
&= 1
130+
^= 1
131+
**= 1
132+
.= 1
133+

Zend/zend_operators.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void ZEND_FASTCALL _convert_scalar_to_number(zval *op, zend_bool silent,
199199
if (check && UNEXPECTED(EG(exception))) {
200200
return;
201201
}
202-
zval_dtor(op);
202+
zval_ptr_dtor(op);
203203

204204
if (Z_TYPE(dst) == IS_LONG || Z_TYPE(dst) == IS_DOUBLE) {
205205
ZVAL_COPY_VALUE(op, &dst);
@@ -1305,7 +1305,7 @@ ZEND_API int ZEND_FASTCALL mod_function(zval *result, zval *op1, zval *op2) /* {
13051305
}
13061306

13071307
if (op1 == result) {
1308-
zval_dtor(result);
1308+
zval_ptr_dtor(result);
13091309
}
13101310

13111311
if (op2_lval == -1) {
@@ -1505,7 +1505,7 @@ ZEND_API int ZEND_FASTCALL bitwise_or_function(zval *result, zval *op1, zval *op
15051505
}
15061506

15071507
if (op1 == result) {
1508-
zval_dtor(result);
1508+
zval_ptr_dtor(result);
15091509
}
15101510
ZVAL_LONG(result, op1_lval | op2_lval);
15111511
return SUCCESS;
@@ -1583,7 +1583,7 @@ ZEND_API int ZEND_FASTCALL bitwise_and_function(zval *result, zval *op1, zval *o
15831583
}
15841584

15851585
if (op1 == result) {
1586-
zval_dtor(result);
1586+
zval_ptr_dtor(result);
15871587
}
15881588
ZVAL_LONG(result, op1_lval & op2_lval);
15891589
return SUCCESS;
@@ -1661,7 +1661,7 @@ ZEND_API int ZEND_FASTCALL bitwise_xor_function(zval *result, zval *op1, zval *o
16611661
}
16621662

16631663
if (op1 == result) {
1664-
zval_dtor(result);
1664+
zval_ptr_dtor(result);
16651665
}
16661666
ZVAL_LONG(result, op1_lval ^ op2_lval);
16671667
return SUCCESS;
@@ -1678,7 +1678,7 @@ ZEND_API int ZEND_FASTCALL shift_left_function(zval *result, zval *op1, zval *op
16781678
if (UNEXPECTED((zend_ulong)op2_lval >= SIZEOF_ZEND_LONG * 8)) {
16791679
if (EXPECTED(op2_lval > 0)) {
16801680
if (op1 == result) {
1681-
zval_dtor(result);
1681+
zval_ptr_dtor(result);
16821682
}
16831683
ZVAL_LONG(result, 0);
16841684
return SUCCESS;
@@ -1696,7 +1696,7 @@ ZEND_API int ZEND_FASTCALL shift_left_function(zval *result, zval *op1, zval *op
16961696
}
16971697

16981698
if (op1 == result) {
1699-
zval_dtor(result);
1699+
zval_ptr_dtor(result);
17001700
}
17011701

17021702
ZVAL_LONG(result, op1_lval << op2_lval);
@@ -1714,7 +1714,7 @@ ZEND_API int ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *o
17141714
if (UNEXPECTED((zend_ulong)op2_lval >= SIZEOF_ZEND_LONG * 8)) {
17151715
if (EXPECTED(op2_lval > 0)) {
17161716
if (op1 == result) {
1717-
zval_dtor(result);
1717+
zval_ptr_dtor(result);
17181718
}
17191719
ZVAL_LONG(result, (op1_lval < 0) ? -1 : 0);
17201720
return SUCCESS;
@@ -1732,7 +1732,7 @@ ZEND_API int ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *o
17321732
}
17331733

17341734
if (op1 == result) {
1735-
zval_dtor(result);
1735+
zval_ptr_dtor(result);
17361736
}
17371737

17381738
ZVAL_LONG(result, op1_lval >> op2_lval);
@@ -1794,7 +1794,7 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
17941794
if (UNEXPECTED(Z_STRLEN_P(op1) == 0)) {
17951795
if (EXPECTED(result != op2)) {
17961796
if (result == orig_op1) {
1797-
zval_dtor(orig_op1);
1797+
i_zval_ptr_dtor(result ZEND_FILE_LINE_CC);
17981798
}
17991799
ZVAL_COPY(result, op2);
18001800
}
@@ -1825,7 +1825,7 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /
18251825
result_str = zend_string_alloc(result_len, 0);
18261826
memcpy(ZSTR_VAL(result_str), Z_STRVAL_P(op1), op1_len);
18271827
if (result == orig_op1) {
1828-
zval_dtor(orig_op1);
1828+
i_zval_ptr_dtor(result ZEND_FILE_LINE_CC);
18291829
}
18301830
}
18311831

0 commit comments

Comments
 (0)