php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40260 PDO causing segfault in PHP
Submitted: 2007-01-28 00:19 UTC Modified: 2007-01-28 14:33 UTC
From: kyle at grishlan dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.2.0 OS: Linux-Gentoo
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kyle at grishlan dot com
New email:
PHP Version: OS:

 

 [2007-01-28 00:19 UTC] kyle at grishlan dot com
Description:
------------
I have a PDO object connecting to a MySQL database, and I pass the object to the __construct function of a new object.  In the __construct function, I attempt to make prepared statement with the PDO object, and if I then exit(1) or die(), without unsetting the PDOStatement object, PHP segfaults.

This is a similar bug to http://bugs.php.net/bug.php?id=37445 (In that it has the same final few functions in the backtrace), but I don't believe it to be the same issue.  I have also tried (per that bug's comments) mysql_statement.c versions 1.48.2.12, 1.48.2.13, 1.48.2.14, and 1.48.2.14.2.2, but they've all reproduced the problem.

My PHP is version 5.1.6-r6 (I'm not running 5.2+ as it's not currently in the gentoo repository.

Reproduce code:
---------------
<?php
class MyClass
{
    public function __construct($pdo)
    {
            $stmt = $pdo->prepare("SELECT * FROM my_table_name");
            $stmt->execute();
            while ($row = $stmt->fetch())
                print_r($row);
            $stmt->closeCursor();
            // Commenting this out makes PHP segfault
            unset($stmt);
            // Commenting this out (if commented above) fixes the segfault
            exit(1);
    }
};
$pdo = new PDO('mysql:host=localhost;dbname=my_db_name', 'root', '');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
$myclass = new MyClass($pdo);
?>

Expected result:
----------------
No output.

Actual result:
--------------
Segmentation fault (backtrace provided below)

(gdb) backt
#0  0xb76566ae in mysql_more_results (mysql=0x5a5a5a5a) at libmysql.c:5136
#1  0x081cd839 in pdo_mysql_stmt_dtor (stmt=0x87fb374)
    at /var/tmp/portage/php-5.1.6-r6/work/php-5.1.6/ext/pdo_mysql/mysql_statement.c:71
#2  0x081c5897 in free_statement (stmt=0x87fb374)
    at /var/tmp/portage/php-5.1.6-r6/work/php-5.1.6/ext/pdo/pdo_stmt.c:2200
#3  0x08309d58 in zend_objects_store_free_object_storage (objects=0x86815ec)
    at /var/tmp/portage/php-5.1.6-r6/work/php-5.1.6/Zend/zend_objects_API.c:86
#4  0x082e23bb in shutdown_executor ()
    at /var/tmp/portage/php-5.1.6-r6/work/php-5.1.6/Zend/zend_execute_API.c:281
#5  0x082eddfd in zend_deactivate ()
    at /var/tmp/portage/php-5.1.6-r6/work/php-5.1.6/Zend/zend.c:854
#6  0x082aa5a3 in php_request_shutdown (dummy=0x0)
    at /var/tmp/portage/php-5.1.6-r6/work/php-5.1.6/main/main.c:1292
#7  0x0837e7aa in main (argc=2, argv=0xbf910804)
    at /var/tmp/portage/php-5.1.6-r6/work/php-5.1.6/sapi/cli/php_cli.c:1246

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-28 01:12 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2007-01-28 02:46 UTC] kyle at grishlan dot com
Using 5.2 appears to fix this bug, thank you.
 [2007-01-28 14:33 UTC] nlopess@php.net
closing then.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC