Edit report at https://bugs.php.net/bug.php?id=53626&edit=1
ID: 53626
Updated by: cmb@php.net
Reported by: bion at drewcrawfordapps dot com
Summary: SQLite3 - Segmentation Fault on shutdown
-Status: Verified
+Status: Analyzed
Type: Bug
-Package: Reproducible crash
+Package: SQLite related
Operating System: Mac OS X 10.7.1
PHP Version: 5.5.0RC2
Block user comment: N
Private report: N
New Comment:
The issue is that ext/sqlite3 has circular references between
SQLite3 and SQLite3Stmt objects, and in case of "unclean shutdown"
(as caused by a catchable fatal error, in this case) the free
handlers are called in order of object construction in PHP 5.
Therefore the SQLite3 object is destroyed, but shortly thereafter
the SQLite3Stmt object tries to access it, which can result in a
segfault (and would be an invalid access, anyway).
As of PHP 7.0.0 the free handlers are invoked in opposite order
of construction, so at least with the given test script there are
no issues.
Anyhow, it seems to me that ext/sqlite3 should better separate
concerns by using dtors and free handlers (currently only free
handlers are used).
Previous Comments:
------------------------------------------------------------------------
[2013-05-23 19:20:44] bion at drewcrawfordapps dot com
This continues to haunt me
------------------------------------------------------------------------
[2012-04-23 17:11:55] bugman at mailinator dot com
I was having the same problem. Apparently it is due to the sqlite3 extension
being threaded, but php not being compiled with the pthread library. I was able
to fix it in FreeBSD by recompiling php with the following option:
LINKTHR Link thread lib (for threaded extensions)
------------------------------------------------------------------------
[2011-12-02 12:12:08] sb at litepc dot com
Additional Info: reducing extensions.ini to only sqlite3.so (no other modules loaded) also gave the
Segmentation fault when executing /usr/local/bin/php-cgi -v
------------------------------------------------------------------------
[2011-12-02 08:33:23] sb at litepc dot com
I get a segfault whenever php-cgi exits even without using sqlite functions.
FreeBSD. Latest Ports as of 1/12/2011
php5-5.3.8
php5-pdo_sqlite-5.3.8
php5-sqlite-5.3.8
php5-sqlite3-5.3.8
sqlite3-3.7.9
# /usr/local/bin/php-cgi -v
PHP 5.3.8 with Suhosin-Patch (cgi-fcgi) (built: Dec 1 2011 22:33:51)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
Segmentation fault
#
Editing extensions.ini to comment out sqlite3.so *and* pdo_sqlite.so eliminates the Segmentation
fault error.
With respect to: "This is due the destructor order."
I have tried many permutations of ordering in extensions.ini but found no case where enabling
sqlite3.so or pdo_sqlite.so worked in any position.
Can not recompile with debug yet as this is a production machine... but will attempt to reproduce in
test scenario and update.
------------------------------------------------------------------------
[2011-09-23 04:55:13] bion at drewcrawfordapps dot com
This bug is still reproducible, and in fact has regressed, since I no longer get a
helpful console error message, but a generic crash report. What are the chances of
getting this fixed?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=53626
--
Edit this bug report at https://bugs.php.net/bug.php?id=53626&edit=1