From dffffdeb3df0b05e79213e52667f3061dc9d635e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 1 Sep 2012 20:31:40 +0200 Subject: [PATCH] Fix leak when yielding array as key The code was copy-pasted and I forgot to change OP1 to OP2 in that one place. --- Zend/tests/generators/yield_array_key.phpt | 18 ++++++++++++++++++ Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 16 ++++++++-------- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 Zend/tests/generators/yield_array_key.phpt diff --git a/Zend/tests/generators/yield_array_key.phpt b/Zend/tests/generators/yield_array_key.phpt new file mode 100644 index 00000000000..5afba00de83 --- /dev/null +++ b/Zend/tests/generators/yield_array_key.phpt @@ -0,0 +1,18 @@ +--TEST-- +Array keys can be yielded from generators +--FILE-- + 1; +} + +$gen = gen(); +var_dump($gen->key()); +var_dump($gen->current()); + +?> +--EXPECT-- +array(0) { +} +int(1) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index ffd81b03785..f683ff29727 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5511,7 +5511,7 @@ ZEND_VM_HANDLER(160, ZEND_YIELD, CONST|TMP|VAR|CV|UNUSED, CONST|TMP|VAR|CV|UNUSE INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!IS_OP1_TMP_FREE()) { + if (!IS_OP2_TMP_FREE()) { zval_copy_ctor(copy); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index b0e05b1296a..f8a89050400 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -5005,7 +5005,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_CONST_TMP_HANDLER(ZEND_OPCODE_HANDLER_ INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!0) { + if (!1) { zval_copy_ctor(copy); } @@ -9553,7 +9553,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_CONST_HANDLER(ZEND_OPCODE_HANDLER_ INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!1) { + if (!0) { zval_copy_ctor(copy); } @@ -11266,7 +11266,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_VAR_HANDLER(ZEND_OPCODE_HANDLER_AR INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!1) { + if (!0) { zval_copy_ctor(copy); } @@ -11846,7 +11846,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_UNUSED_HANDLER(ZEND_OPCODE_HANDLER INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!1) { + if (!0) { zval_copy_ctor(copy); } @@ -12537,7 +12537,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_TMP_CV_HANDLER(ZEND_OPCODE_HANDLER_ARG INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!1) { + if (!0) { zval_copy_ctor(copy); } @@ -18543,7 +18543,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER_AR INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!0) { + if (!1) { zval_copy_ctor(copy); } @@ -27081,7 +27081,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_UNUSED_TMP_HANDLER(ZEND_OPCODE_HANDLER INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!0) { + if (!1) { zval_copy_ctor(copy); } @@ -35600,7 +35600,7 @@ static int ZEND_FASTCALL ZEND_YIELD_SPEC_CV_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG INIT_PZVAL_COPY(copy, key); /* Temporary variables don't need ctor copying */ - if (!0) { + if (!1) { zval_copy_ctor(copy); }