Bug #69549 [Ana]: Memory leak with opcache.optimization_level=0xFFFFFFFF

From: Date: Thu, 30 Apr 2015 16:28:59 +0000
Subject: Bug #69549 [Ana]: Memory leak with opcache.optimization_level=0xFFFFFFFF
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192430@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69549&edit=1 ID: 69549 Updated by: laruence@php.net Reported by: naoki-kawamukai at cybozu dot co dot jp Summary: Memory leak with opcache.optimization_level=0xFFFFFFFF Status: Analyzed Type: Bug Package: opcache Operating System: Debian 7.8 PHP Version: 5.5Git-2015-04-30 (Git) Assigned To: dmitry Block user comment: N Private report: N New Comment: A quick fix is attached(which could show where the problem is) diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c index 113a41c..214aeee 100644 --- a/ext/opcache/Optimizer/block_pass.c +++ b/ext/opcache/Optimizer/block_pass.c @@ -1627,7 +1627,7 @@ next_target: if (block->op2_to) { zend_op *target, *target_end; - char *same_t=NULL; + char *same_t = NULL; zend_code_block *target_block; int var_num = 0; if (op_array->T >= (zend_uint)op_array->last_var) { @@ -1760,12 +1760,19 @@ next_target_ex: } else if (block->op2_to == block->ext_to) { /* both goto the same one - it's JMP */ /* JMPZNZ(?,L,L) -> JMP(L) */ - last_op->opcode = ZEND_JMP; - SET_UNUSED(last_op->op1); - SET_UNUSED(last_op->op2); - block->op1_to = block->op2_to; - block->op2_to = NULL; - block->ext_to = NULL; + if (last_op->op1_type == IS_VAR) { + last_op->opcode = ZEND_JMPZ; + block->follow_to = block->op2_to; + block->op1_to = NULL; + block->ext_to = NULL; + } else { + last_op->opcode = ZEND_JMP; + SET_UNUSED(last_op->op1); + SET_UNUSED(last_op->op2); + block->op1_to = block->op2_to; + block->op2_to = NULL; + block->ext_to = NULL; + } } else if (block->op2_to == next) { /* jumping to next on Z - can follow to it and jump only on NZ */ /* JMPZNZ(X,L1,L2) L1: -> JMPNZ(X,L2) */ thanks Previous Comments: ------------------------------------------------------------------------ [2015-04-30 12:08:49] laruence@php.net instead of fix optimization in cfg .. maybe we should insert some ZEND_FREE, considering following test script, the FETCH_OBJ_R should not be optimized away: <?php class A { public function __get($name) { echo "__get: $name"; return "$name"; } } $a = new A; if ($a->true && false) { echo "bad"; } thanks ------------------------------------------------------------------------ [2015-04-30 03:01:59] laruence@php.net side affects by block pass optimization.. ------------------------------------------------------------------------ [2015-04-30 02:05:26] naoki-kawamukai at cybozu dot co dot jp Description: ------------ This leaks occurs on PHP 5.5(Git-2015-04-30), PHP 5.6(Git-2015-04-30). But it does not occur on PHP 7.0(Git-2015-04-30) My opcache configuration: vagrant@php7dev:~$ php -i | grep opcache opcache.blacklist_filename => no value => no value opcache.consistency_checks => 0 => 0 opcache.dups_fix => Off => Off opcache.enable => On => On opcache.enable_cli => Off => Off opcache.enable_file_override => Off => Off opcache.error_log => no value => no value opcache.fast_shutdown => 1 => 1 opcache.file_update_protection => 2 => 2 opcache.force_restart_timeout => 180 => 180 opcache.inherited_hack => On => On opcache.interned_strings_buffer => 8 => 8 opcache.load_comments => 1 => 1 opcache.log_verbosity_level => 1 => 1 opcache.max_accelerated_files => 10000 => 10000 opcache.max_file_size => 0 => 0 opcache.max_wasted_percentage => 5 => 5 opcache.memory_consumption => 256 => 256 opcache.optimization_level => 0xFFFFFFFF => 0xFFFFFFFF opcache.preferred_memory_model => no value => no value opcache.protect_memory => 0 => 0 opcache.restrict_api => no value => no value opcache.revalidate_freq => 2 => 2 opcache.revalidate_path => Off => Off opcache.save_comments => 1 => 1 opcache.use_cwd => On => On opcache.validate_timestamps => On => On Test script: --------------- <?php $a = array(true); if($a[0] && false) { echo 'test'; } ?> Expected result: ---------------- Nothing happen. Actual result: -------------- Memory leaks. vagrant@php7dev:~$ php -d opcache.enable_cli=1 -d opcache.optimization_level=0xFFFFFFFF leak.php [Thu Apr 30 01:42:30 2015] Script: '/home/vagrant/leak.php' /home/vagrant/php-src/Zend/zend_vm_execute.h(6257) : Freeing 0x7F6A57B167E0 (32 bytes), script=/home/vagrant/leak.php === Total 1 memory leaks detected === When disabling opcache optimization, memory does not leak. vagrant@php7dev:~$ php -d opcache.enable_cli=1 -d opcache.optimization_level=0 leak.php ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69549&edit=1

« previous php.bugs (#192430) next »