From c71ab607ffe7139cf01ecd0a49f1e40ca9f71da2 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 26 Aug 2014 19:39:40 +0200 Subject: [PATCH] Don't alloc empty jmp opnum list for single-branch if --- Zend/zend_compile.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5e2455960b..15edc7c380 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4897,7 +4897,11 @@ void zend_compile_foreach(zend_ast *ast TSRMLS_DC) { void zend_compile_if(zend_ast *ast TSRMLS_DC) { zend_ast_list *list = zend_ast_get_list(ast); uint32_t i; - uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0); + uint32_t *jmp_opnums; + + if (list->children > 1) { + jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0); + } for (i = 0; i < list->children; ++i) { zend_ast *elem_ast = list->child[i]; @@ -4922,11 +4926,12 @@ void zend_compile_if(zend_ast *ast TSRMLS_DC) { } } - for (i = 0; i < list->children - 1; ++i) { - zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC); + if (list->children > 1) { + for (i = 0; i < list->children - 1; ++i) { + zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC); + } + efree(jmp_opnums); } - - efree(jmp_opnums); } void zend_compile_switch(zend_ast *ast TSRMLS_DC) { -- 2.50.1