zephir: Memory Error in Debug Mode with Exception on method Assignment in PHP5.6
Running in debug mode (Using phalcon’s ./ext/install-test
mode) with latest Zephir, PHP5.6 results in errors in the dispatcher because of Zephir not releasing variable when exception is thrown inside an assignment.
Essentially the next access to the variable … either in the catch, or in a subsequent loop will cause the error.
tester.zep
class Tester
{
public function testMemoryException()
{
var e, status;
printf(">>> dispatchTest()\n");
try {
let status = this->doNoopException();
} catch \Exception, e {
printf (">>> Caught exception: %s\n", e->getMessage());
// Throws fatal variable is already observed. Note, the above call must be a
// method that assigns to variable in order for exception to occur.
let status = "woop";
}
printf(">>> after dispatchTest() (Should not get here in debug mode)\n");
}
private function doNoopException()
{
printf(">>> doNoopException()\n");
throw new \Exception("I am exception");
}
}
test.php
<?php
$tester = new Tester();
$tester->testMemoryException();
OUTPUT
# php test.php
>>> dispatchTest()
>>> doNoopException()
>>> Caught exception: I am exception
Variable 0x7ffebe09d580 is already observed
Dump of the memory frame 0x7f26ac8941d0 ((null))
Obs var 1 (0x7ffebe09d588 => 0x7f26a9f9db20), type=5, refcnt=1; value=object(2), Exception
Obs var 2 (0x7ffebe09d558 => 0x7f26a9f9f758), type=6, refcnt=1; value=I am exception (0x7f26a9f9f788)
End of the dump of the memory frame 0x7f26ac8941d0
#0 0x7f26905c7b3d [/usr/lib64/php/modules/phalcon.so(+0x69a3b3d) [0x7f26905c7b3d]]
#1 0x7f26905c4b7d [/usr/lib64/php/modules/phalcon.so(+0x69a0b7d) [0x7f26905c4b7d]]
#2 0x7f26905c4c26 [/usr/lib64/php/modules/phalcon.so(+0x69a0c26) [0x7f26905c4c26]]
#3 0x7f269066fc14 [/usr/lib64/php/modules/phalcon.so(+0x6a4bc14) [0x7f269066fc14]]
#4 0x7f26aa1f51eb [php(dtrace_execute_internal+0x2b) [0x7f26aa1f51eb]]
#5 0x7f26aa2aee94 [php(+0x2ece94) [0x7f26aa2aee94]]
#6 0x7f26aa2431d8 [php(execute_ex+0x38) [0x7f26aa2431d8]]
#7 0x7f26aa1f50c9 [php(dtrace_execute_ex+0x79) [0x7f26aa1f50c9]]
#8 0x7f26aa207e6b [php(zend_execute_scripts+0x18b) [0x7f26aa207e6b]]
#9 0x7f26aa1a2dd2 [php(php_execute_script+0x282) [0x7f26aa1a2dd2]]
#10 0x7f26aa2b0da8 [php(+0x2eeda8) [0x7f26aa2b0da8]]
#11 0x7f26aa07e05a [php(+0xbc05a) [0x7f26aa07e05a]]
#12 0x7f26a6b53b15 [/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f26a6b53b15]]
#13 0x7f26aa07e0f5 [php(+0xbc0f5) [0x7f26aa07e0f5]]
gdb backtrace
#0 0x00007ffff4ba45f7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007ffff4ba5ce8 in __GI_abort () at abort.c:90
#2 0x00007fffde601b82 in zephir_do_memory_observe (var=0x7fffffffa740, g=0x7fffe64de6a0 <phalcon_globals>) at /usr/share/cphalcon/ext/kernel/memory.c:550
#3 0x00007fffde601c26 in zephir_memory_alloc (var=0x7fffffffa740) at /usr/share/cphalcon/ext/kernel/memory.c:576
#4 0x00007fffde6acc14 in zim_Tester_testMemoryException (ht=0, return_value=0x7ffff7fd9c50, return_value_ptr=0x7ffff7fa40c0, this_ptr=0x7ffff7fd7f10, return_value_used=0) at /usr/share/cphalcon/ext/phalcon/tester.zep.c:31
#5 0x00005555557871eb in dtrace_execute_internal (execute_data_ptr=<optimized out>, fci=<optimized out>, return_value_used=<optimized out>) at /usr/src/debug/php-5.6.25/Zend/zend_dtrace.c:97
#6 0x0000555555840e94 in zend_do_fcall_common_helper_SPEC (execute_data=<optimized out>) at /usr/src/debug/php-5.6.25/Zend/zend_vm_execute.h:560
#7 0x00005555557d51d8 in execute_ex (execute_data=0x7ffff7fa4178) at /usr/src/debug/php-5.6.25/Zend/zend_vm_execute.h:363
#8 0x00005555557870c9 in dtrace_execute_ex (execute_data=<optimized out>) at /usr/src/debug/php-5.6.25/Zend/zend_dtrace.c:73
#9 0x0000555555799e6b in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0, file_count=file_count@entry=3) at /usr/src/debug/php-5.6.25/Zend/zend.c:1341
#10 0x0000555555734dd2 in php_execute_script (primary_file=primary_file@entry=0x7fffffffce30) at /usr/src/debug/php-5.6.25/main/main.c:2613
#11 0x0000555555842da8 in do_cli (argc=2, argv=0x555555b97030) at /usr/src/debug/php-5.6.25/sapi/cli/php_cli.c:994
#12 0x000055555561005a in main (argc=2, argv=0x555555b97030) at /usr/src/debug/php-5.6.25/sapi/cli/php_cli.c:1378
EXPECTED OUTPUT
# php test.php
>>> dispatchTest()
>>> doNoopException()
>>> Caught exception: I am exception
>>> after dispatchTest() (Should not get here in debug mode)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (7 by maintainers)
Commits related to this issue
- Fix #1325 (ZE2) — committed to sjinks/zephir by sjinks 7 years ago
- Fix #1325 (ZE2) — committed to sjinks/zephir by sjinks 7 years ago
- Fix #1325 (ZE3) — committed to sjinks/zephir by sjinks 7 years ago
- Fix #1325 (ZE3) — committed to sjinks/zephir by sjinks 7 years ago
- Merge pull request #1485 from sjinks/issue-1325 Fix assignment after exception (#1325) — committed to zephir-lang/zephir by sjinks 7 years ago
Fixed in b7fa2f45bb281039d56f7421ae90dfc2edfcf9d7