zephir-lang / zephir

Zephir is a compiled high-level language aimed to ease the creation of C-extensions for PHP
https://zephir-lang.com
MIT License
3.3k stars 466 forks source link

Crash on shutdown #1489

Closed sjinks closed 7 years ago

sjinks commented 7 years ago
$ UZE_ZEND_ALLOC=0 gdb --args $(phpenv which php) ./unit-tests/phpunit --not-exit -c phpunit.xml.dist unit-tests/
GNU gdb (Ubuntu 7.11.90.20161005-0ubuntu1) 7.11.90.20161005-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/vladimir/.phpenv/versions/7.0.9-debug-nts/bin/php...done.
(gdb) run
Starting program: /home/vladimir/.phpenv/versions/7.0.9-debug-nts/bin/php ./unit-tests/phpunit --not-exit -c phpunit.xml.dist unit-tests/
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

Runtime:        PHP 7.0.9
Configuration:  /home/vladimir/workspace/zephir/phpunit.xml.dist

...............................................................  63 / 346 ( 18%)
............................................................... 126 / 346 ( 36%)
............................................................... 189 / 346 ( 54%)
............................................................... 252 / 346 ( 72%)
............................................................... 315 / 346 ( 91%)
...............................

Time: 835 ms, Memory: 10.00MB

OK (346 tests, 1453 assertions)

Program received signal SIGSEGV, Segmentation fault.
0x0000555555c97a36 in zend_string_release (s=0x0) at /tmp/php-build/source/7.0.9/Zend/zend_string.h:269
269     /tmp/php-build/source/7.0.9/Zend/zend_string.h: Немає такого файла або каталогу.
(gdb) bt
#0  0x0000555555c97a36 in zend_string_release (s=0x0) at /tmp/php-build/source/7.0.9/Zend/zend_string.h:269
#1  0x0000555555c98c02 in destroy_op_array (op_array=0x7fffeae79468) at /tmp/php-build/source/7.0.9/Zend/zend_opcode.c:369
#2  0x0000555555c97f60 in zend_function_dtor (zv=0x7fffeaeaa040) at /tmp/php-build/source/7.0.9/Zend/zend_opcode.c:124
#3  0x0000555555cc1d78 in zend_hash_destroy (ht=0x7fffeae79270) at /tmp/php-build/source/7.0.9/Zend/zend_hash.c:1265
#4  0x0000555555c988ba in destroy_zend_class (zv=0x7fffffffb2a0) at /tmp/php-build/source/7.0.9/Zend/zend_opcode.c:289
#5  0x0000555555cc1427 in _zend_hash_del_el_ex (ht=0x5555566f2390, idx=875, p=0x55555691b1e0, prev=0x0) at /tmp/php-build/source/7.0.9/Zend/zend_hash.c:1026
#6  0x0000555555cc1507 in _zend_hash_del_el (ht=0x5555566f2390, idx=875, p=0x55555691b1e0) at /tmp/php-build/source/7.0.9/Zend/zend_hash.c:1050
#7  0x0000555555cc2e03 in zend_hash_reverse_apply (ht=0x5555566f2390, apply_func=0x555555c91afa <clean_non_persistent_class>) at /tmp/php-build/source/7.0.9/Zend/zend_hash.c:1628
#8  0x0000555555c9287e in shutdown_executor () at /tmp/php-build/source/7.0.9/Zend/zend_execute_API.c:367
#9  0x0000555555cab0f7 in zend_deactivate () at /tmp/php-build/source/7.0.9/Zend/zend.c:967
#10 0x0000555555c138cc in php_request_shutdown (dummy=0x0) at /tmp/php-build/source/7.0.9/main/main.c:1833
#11 0x0000555555d74ea9 in do_cli (argc=6, argv=0x5555566f1fb0) at /tmp/php-build/source/7.0.9/sapi/cli/php_cli.c:1141
#12 0x0000555555d75725 in main (argc=6, argv=0x5555566f1fb0) at /tmp/php-build/source/7.0.9/sapi/cli/php_cli.c:1344

PHP 7.0.9 NTS DEBUG

sjinks commented 7 years ago
(gdb) frame 4
(gdb) print (char*)((zend_class_entry*)zv->value.ptr)->name->val
$1 = 0x7fffeb24cd98 "PHPUnit_Framework_Constraint_IsType"
sjinks commented 7 years ago

Related to #1488

sjinks commented 7 years ago
--- a/kernels/ZendEngine3/memory.c
+++ b/kernels/ZendEngine3/memory.c
@@ -400,7 +400,7 @@ void zephir_create_symbol_table()
    entry->symbol_table = ex->symbol_table;
    entry->prev         = gptr->active_symbol_table;

-   symbol_table = (zend_array*)emalloc(sizeof(zend_array *));
+   symbol_table = (zend_array*)emalloc(sizeof(zend_array));
    zend_hash_init(symbol_table, 0, NULL, ZVAL_PTR_DTOR, 0);
    zend_hash_real_init(symbol_table, 0);