php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56360 yet another shutdown problem
Submitted: 2005-03-27 16:10 UTC Modified: 2005-06-18 02:02 UTC
From: lmpmbernardo at users dot sourceforge dot net Assigned:
Status: Closed Package: PDO_MYSQL (PECL)
PHP Version: 5_0 CVS-2005-03-27 (dev) OS: Fedora Core 2
Private report: No CVE-ID: None
 [2005-03-27 16:10 UTC] lmpmbernardo at users dot sourceforge dot net
Description:
------------
Using most recent PDO (0.3) and PDO_MYSQL (0.2).
Configuration: './configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-mysql=/usr/local/mysql4/' '--with-mysqli=/usr/local/mysql4/bin/mysql_config' '--with-xmlrpc' '--with-zlib'
Problem: calling PDO::lastInsertId() causes segmentation fault.

Reproduce code:
---------------
$db = new PDO("mysql:dbname=test;host=127.0.0.1", "root", "");
echo "Successfully created a PDO object";
$db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
try {
    $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL auto_increment, name VARCHAR(20), PRIMARY KEY (id))";
    $db->query($sql);
} catch(Exception $e) {
    // ok; db created before...
}
$name = "XXXXXX";
$sql = "INSERT INTO pdobomb(id, name) VALUES(null, '$name')";
$db->query($sql);
$id = $db->lastInsertId(); // offending call
echo $id;


Expected result:
----------------
Expect: no segmentation fault; output of last inserted id.

Actual result:
--------------
I was not succesfull in compiling PDO with the debug switch. Not sure why... In any case below is a backtrace that may be of use.

[lmpmbernardo@antonio tmp]$ php -v
PHP 5.1.0-dev (cli) (built: Mar 27 2005 13:27:38)
Copyright (c) 1997-2005 The PHP Group
Zend Engine v2.1.0-dev, Copyright (c) 1998-2004 Zend Technologies
    with Xdebug v2.0.0beta2, Copyright (c) 2002, 2003, 2004, by Derick Rethans
[lmpmbernardo@antonio tmp]$ cat /home/lmpmbernardo/workspace/pdotest/pdodebug.php
<?php
 
$db = new PDO("mysql:dbname=test;host=127.0.0.1", "root", "");
echo "Successfully created a PDO object";
$db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
try {
    $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL auto_increment, name VARCHAR(20), PRIMARY KEY (id))";
    $db->query($sql);
} catch(Exception $e) {
    // ok; db created before...
}
$name = "XXXXXX";
$sql = "INSERT INTO pdobomb(id, name) VALUES(null, '$name')";
$db->query($sql);
$id = $db->lastInsertId();
echo $id;
 
?>
[lmpmbernardo@antonio tmp]$ gdb php
GNU gdb Red Hat Linux (6.0post-0.20040223.19rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
 
(gdb) run /home/lmpmbernardo/workspace/pdotest/pdodebug.php
Starting program: /usr/local/bin/php /home/lmpmbernardo/workspace/pdotest/pdodebug.php
[Thread debugging using libthread_db enabled]
[New Thread -1208597408 (LWP 1941)]
Successfully created a PDO object
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208597408 (LWP 1941)]
_efree (ptr=0xe) at /tmp/php5-200503262330/Zend/zend_alloc.c:285
285             CALCULATE_REAL_SIZE_AND_CACHE_INDEX(p->size);
(gdb) bt
#0  _efree (ptr=0xe) at /tmp/php5-200503262330/Zend/zend_alloc.c:285
#1  0x0817ee79 in _zval_ptr_dtor (zval_ptr=0x8784dc0) at zend_variables.h:35
#2  0x0818d7a4 in zend_hash_apply_deleter (ht=0x8245c50, p=0x8784db4) at /tmp/php5-200503262330/Zend/zend_hash.c:574
#3  0x0818d816 in zend_hash_graceful_reverse_destroy (ht=0x8245c50) at /tmp/php5-200503262330/Zend/zend_hash.c:640
#4  0x0817ed4a in shutdown_executor () at /tmp/php5-200503262330/Zend/zend_execute_API.c:216
#5  0x08187da8 in zend_deactivate () at /tmp/php5-200503262330/Zend/zend.c:823
#6  0x08158832 in php_request_shutdown (dummy=0x0) at /tmp/php5-200503262330/main/main.c:1217
#7  0x081e676b in main (argc=2, argv=0xbfef8f74) at /tmp/php5-200503262330/sapi/cli/php_cli.c:1057
(gdb) quit
The program is running.  Exit anyway? (y or n) y
[lmpmbernardo@antonio tmp]$


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-08 00:31 UTC] lmpmbernardo at users dot sourceforge dot net
I see the same problem with Fedora 4 Test 3. The installation was done through rpms, except for the PDO related extensions and xdebug that I compiled myself. The lastInsertId problem exists with the pdo_mysql extension (on Fedora; on Windows works fine) but not with the pdo_sqlite extension. I think this should be fixed before 5.1 comes out... Here is another screen dump:

[root@antonio tmp]# rpm -qa | grep php
php-ldap-5.0.4-10
php-debuginfo-5.0.4-10
php-mysql-5.0.4-10
php-devel-5.0.4-10
php-pear-5.0.4-10
php-5.0.4-10
php-odbc-5.0.4-10
[root@antonio tmp]# php -v
PHP 5.0.4 (cli) (built: May  9 2005 11:21:11)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
    with Xdebug v2.0.0beta2, Copyright (c) 2002, 2003, 2004, by Derick Rethans
[root@antonio tmp]# php -m
[PHP Modules]
bz2
calendar
ctype
curl
dbx
dio
exif
ftp
gettext
gmp
iconv
ldap
libxml
mime_magic
mysql
mysqli
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
posix
pspell
session
shmop
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xdebug
xml
yp
zlib

[Zend Modules]
Xdebug

[root@antonio tmp]# cat /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php
<?php
/**
 * $Id$
 * @package pdotest
 */

$db = new PDO("mysql:dbname=test;host=127.0.0.1", "root", "");
//$db = new PDO("sqlite:/tmp/test.db", "", "");
echo "Successfully created a PDO object";
$db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
//$sql = "DROP TABLE pdobomb";
//$db->query($sql);
try {
    $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL auto_increment, name VARCHAR(20), PRIMARY KEY (id))";
//    $sql = "CREATE TABLE pdobomb(id INT(11) NOT NULL INTEGER, name VARCHAR(20), PRIMARY KEY (id))";
    $db->exec($sql);
} catch(Exception $e) {
    // ok; db created before...
}
$name = "YYYYYY";
$sql = "INSERT INTO pdobomb(id, name) VALUES(null, '$name')";
$db->exec($sql);
$id = $db->lastInsertId();
echo $id;

?>
[root@antonio tmp]# gdb php
GNU gdb Red Hat Linux (6.3.0.0-1.24rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) run /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php
Starting program: /usr/bin/php /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x5dc000
[Thread debugging using libthread_db enabled]
[New Thread -1208394880 (LWP 12293)]
Successfully created a PDO object
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208394880 (LWP 12293)]
_efree (ptr=0x9) at /usr/src/debug/php-5.0.4/Zend/zend_alloc.c:263
263             CALCULATE_REAL_SIZE_AND_CACHE_INDEX(p->size);
(gdb) quit
The program is running.  Exit anyway? (y or n) y
 [2005-06-08 00:56 UTC] lmpmbernardo at users dot sourceforge dot net
forgot the backtrace....

(gdb) run /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php
Starting program: /usr/bin/php /home/lmpmbernardo/eclipseworks/pdotest/pdodebug.php
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0xc50000
[Thread debugging using libthread_db enabled]
[New Thread -1208501376 (LWP 13244)]
Successfully created a PDO object
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208501376 (LWP 13244)]
_efree (ptr=0xa) at /usr/src/debug/php-5.0.4/Zend/zend_alloc.c:263
263             CALCULATE_REAL_SIZE_AND_CACHE_INDEX(p->size);
(gdb) bt
#0  _efree (ptr=0xa) at /usr/src/debug/php-5.0.4/Zend/zend_alloc.c:263
#1  0x08168e3c in _zval_ptr_dtor (zval_ptr=0x8939ce8) at /usr/src/debug/php-5.0.4/Zend/zend_execute_API.c:392
#2  0x08179ffc in zend_hash_apply_deleter (ht=0x8218230, p=0x8939cdc) at /usr/src/debug/php-5.0.4/Zend/zend_hash.c:574
#3  0x0817a116 in zend_hash_graceful_reverse_destroy (ht=0x8218230) at /usr/src/debug/php-5.0.4/Zend/zend_hash.c:640
#4  0x08169a60 in shutdown_executor () at /usr/src/debug/php-5.0.4/Zend/zend_execute_API.c:208
#5  0x081740de in zend_deactivate () at /usr/src/debug/php-5.0.4/Zend/zend.c:817
#6  0x0813e197 in php_request_shutdown (dummy=0x0) at /usr/src/debug/php-5.0.4/main/main.c:1216
#7  0x081a7895 in main (argc=2, argv=0xbf9950d4) at /usr/src/debug/php-5.0.4/sapi/cli/php_cli.c:1049
(gdb) quit
The program is running.  Exit anyway? (y or n) y
 [2005-06-10 02:29 UTC] wez@php.net
Looks to me like this is another case of the ZE shutting things down in the wrong order.

Can you try the latest stable snapshot of PHP from http://snaps.php.net and see if the problem persists?
 [2005-06-18 02:02 UTC] lmpmbernardo at users dot sourceforge dot net
yep, the problem is not there anymore. thanks. tested with php-5.1.x (php5-200506180430) on Fedora Core 4 Test 3. I closed the issue.
 [2007-10-18 18:59 UTC] fdf at fgh dot hgj
http://www.forex.co.ir
http://www.meta-fx.com
forex    ?????
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 22:03:39 2021 UTC