Opened 8 years ago

Closed 8 years ago

#748 closed defect (fixed)

PHP7 bindings segfaults

Reported by: Victor Sakovich Owned by: Olly Betts
Priority: normal Milestone: 1.4.4
Component: Xapian-bindings (PHP) Version: 1.4.3
Severity: normal Keywords: PHP7
Cc: Blocked By:
Blocking: Operating System: Linux

Description

I have issue while running Xapian with CentOS7 x86_64. My environment is:

~ cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
~ rpm  -qa | grep php
php71w-common-7.1.2-1.w7.x86_64
php71w-cli-7.1.2-1.w7.x86_64
xapian-bindings-php7-1.4.3-1.el7.x86_64
~ php -i | grep -A 3 Xapian
Xapian Support => enabled
Xapian Compiled Version => 1.4.3
Xapian Linked Version => 1.4.3

PHP packages are taken from https://webtatic.com/projects/yum-repository/ , and Xapian packages are compiled from the source.

The issue is that PHP segfaults. For example "gdb php" run with "-i" option results in:

Program received signal SIGSEGV, Segmentation fault.
0x00005555557e1b09 in _zval_ptr_dtor ()
(gdb) backtrace 
#0  0x00005555557e1b09 in _zval_ptr_dtor ()
#1  0x00005555557e0082 in free_zend_constant ()
#2  0x00005555558038a2 in zend_hash_destroy ()
#3  0x00005555557f2039 in zend_shutdown ()
#4  0x000055555578fffb in php_module_shutdown ()
#5  0x00005555556252c5 in main ()
(gdb) 

Here is additional information as reported by valgrind:

~ USE_ZEND_ALLOC=0 valgrind --tool=memcheck  php -v
==12785== Memcheck, a memory error detector
==12785== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==12785== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==12785== Command: php -v
==12785== 
PHP 7.1.2 (cli) (built: Feb 18 2017 11:22:37) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
==12785== 
==12785== HEAP SUMMARY:
==12785==     in use at exit: 8,107 bytes in 94 blocks
==12785==   total heap usage: 21,692 allocs, 21,598 frees, 2,271,702 bytes allocated
==12785== 
==12785== LEAK SUMMARY:
==12785==    definitely lost: 4,320 bytes in 28 blocks
==12785==    indirectly lost: 2,269 bytes in 36 blocks
==12785==      possibly lost: 0 bytes in 0 blocks
==12785==    still reachable: 1,518 bytes in 30 blocks
==12785==         suppressed: 0 bytes in 0 blocks
==12785== Rerun with --leak-check=full to see details of leaked memory
==12785== 
==12785== For counts of detected and suppressed errors, rerun with: -v
==12785== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Please let me know if you need to provide additional information.

Change History (6)

comment:1 by Victor Sakovich, 8 years ago

I have tried to build the latest Xapian source from https://github.com/xapian/xapian, however has the same issue.

comment:2 by Olly Betts, 8 years ago

From the backtrace, I suspect this SWIG bug: https://github.com/swig/swig/issues/859

If so, you can probably work around this by manually changing 0 to CONST_PERSISTENT | CONST_CS in the definition of SWIG_Php_SetModule in php7/php7/xapian_wrap.cc before compiling.

comment:3 by Victor Sakovich, 8 years ago

This fixed the issue. Thank you. The fix is:

@@ -974,7 +974,7 @@
 }
 
 static void SWIG_Php_SetModule(swig_module_info *pointer) {
-  REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0);
+  REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, CONST_CS | CONST_PERSISTENT);
 }
 
 /*  Errors in SWIG */
Last edited 8 years ago by Victor Sakovich (previous) (diff)

comment:4 by Olly Betts, 8 years ago

Milestone: 1.4.x1.4.4
Owner: set to Olly Betts
Status: newassigned

Fixed in git master by [e196773173d344f108821f68521c15c048eca3fe/git]. Marking for backport for next 1.4 release.

comment:5 by Olly Betts, 8 years ago

And thanks for confirming the fix!

comment:6 by Olly Betts, 8 years ago

Resolution: fixed
Status: assignedclosed

Backported to RELEASE/1.4 in f69805d622aba0c0cf61fd74a362540180388319.

Note: See TracTickets for help on using tickets.