Skip to content

Commit c94f62d

Browse files
committed
Merge branch 'PHP-5.6'
Conflicts: ext/opcache/Optimizer/pass2.c
2 parents 00628af + 87ccf50 commit c94f62d

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Zend/tests/bug67111.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #67111: Memory leak when using "continue 2" inside two foreach loops
3+
--FILE--
4+
<?php
5+
6+
$array1 = [1, 2, 3];
7+
$array2 = [1, 2, 3];
8+
9+
foreach ($array1 as $x) {
10+
foreach ($array2 as $y) {
11+
echo "$x.$y\n";
12+
continue 2;
13+
}
14+
}
15+
16+
?>
17+
--EXPECT--
18+
1.1
19+
2.1
20+
3.1

ext/opcache/Optimizer/pass2.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,10 @@ void zend_optimizer_pass2(zend_op_array *op_array)
189189
int nest_levels;
190190
int dont_optimize = 0;
191191

192-
if (ZEND_OP2_TYPE(opline) != IS_CONST) {
193-
break;
194-
}
195-
convert_to_long(&ZEND_OP2_LITERAL(opline));
196-
nest_levels = ZEND_OP2_LITERAL(opline).value.lval;
192+
ZEND_ASSERT(ZEND_OP2_TYPE(opline) == IS_CONST);
193+
ZEND_ASSERT(Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_LONG);
194+
195+
nest_levels = Z_LVAL(ZEND_OP2_LITERAL(opline));
197196

198197
array_offset = ZEND_OP1(opline).opline_num;
199198
while (1) {
@@ -204,8 +203,7 @@ void zend_optimizer_pass2(zend_op_array *op_array)
204203
jmp_to = &op_array->brk_cont_array[array_offset];
205204
array_offset = jmp_to->parent;
206205
if (--nest_levels > 0) {
207-
if (opline->opcode == ZEND_BRK &&
208-
op_array->opcodes[jmp_to->brk].opcode == ZEND_FREE) {
206+
if (op_array->opcodes[jmp_to->brk].opcode == ZEND_FREE) {
209207
dont_optimize = 1;
210208
break;
211209
}

0 commit comments

Comments
 (0)