From: Nikita Popov Date: Thu, 14 Jul 2016 20:29:04 +0000 (+0200) Subject: Fix leak if get_iterator throws but doesn't return NULL X-Git-Tag: php-7.1.0beta1~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbba1fff3f81bb7c4e6455d2170563e42cca559d;p=php Fix leak if get_iterator throws but doesn't return NULL --- diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 0be1b5726c..161a3f53fa 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5754,6 +5754,9 @@ ZEND_VM_HANDLER(77, ZEND_FE_RESET_R, CONST|TMP|VAR|CV, JMP_ADDR) if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { FREE_OP1(); + if (iter) { + OBJ_RELEASE(&iter->std); + } if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 5943e4b5c7..3df5217514 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -3511,6 +3511,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER( if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + if (iter) { + OBJ_RELEASE(&iter->std); + } if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } @@ -12571,6 +12574,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZE if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { zval_ptr_dtor_nogc(free_op1); + if (iter) { + OBJ_RELEASE(&iter->std); + } if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } @@ -16157,6 +16163,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZE if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { zval_ptr_dtor_nogc(free_op1); + if (iter) { + OBJ_RELEASE(&iter->std); + } if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } @@ -35267,6 +35276,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEN if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { + if (iter) { + OBJ_RELEASE(&iter->std); + } if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); }