php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13136 Crash on shutdown when ODBC connection still open
Submitted: 2001-09-04 12:36 UTC Modified: 2002-03-06 00:00 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: kai dot brockmann at 3und20 dot net Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 4.0.6 OS: Win2000 SP2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kai dot brockmann at 3und20 dot net
New email:
PHP Version: OS:

 

 [2001-09-04 12:36 UTC] kai dot brockmann at 3und20 dot net
I'm working with an Access 2000 database (MDAC 2.6) via ODBC on W2K SP2. The following code 

will cause PHP 4.0.6 to crash with an access violation. The same bahaviour was experienced with version 4.0.2.

Save the two files and open test.php in browser to reproduce. (Sorry, must post long script as I haven't any other place to put it. And I got no gdb.)

-------------------------------------- crash code: test.php
<html>
<body>
<?php

include('test2.php');

 causeAccessViolation();

?>
</body>
</html>
-------------------------------------- crash code: test.php END

-------------------------------------- crash code: test2.php

<?php


function connect()
{

// Put some db here; my DNS was 'eqms'
    $db = odbc_connect('eqms', '', '')
        or die(__FILE__.": Unable to connect to database!");

    return $db;
}

function disconnect($db)
{
    if(isset($db) && $db != 0)
        odbc_close($db);
}

function denyAccess()
{
    echo 'NO ACCESS';
    exit();
}

function causeAccessViolation()
{

$db = connect();
if(!$db)
    die($db_err);


// Put some query here
$query = "SELECT MitarbeiterID, ProjektID
	     FROM
	     ProjektMitarbeiter
	     WHERE
	     MitarbeiterID = 45 AND
         ProjektID = 45";

	     $query_result = odbc_exec($db, $query);
	     if(!$query_result)
		    die($db_err);

	     $row = odbc_fetch_row($query_result);

/* 1     odbc_free_result($query_result);
         disconnect($db);

*/

         denyAccess();

/*  2 COMMENT OUT THE NEXT TWO LINES AND COMMENT IN THE LINES AT 1
    AND PHP WON'T CRASH ANYMORE

*/
                odbc_free_result($query_result);
                disconnect($db);

}


 ?>

-------------------------------------- crash code: test2.php END


I debugged PHP and the results showed that PHP crashed during shutdown somewhere below 

list_entry_destructor() in zend_list.c:

----------------- snippet zend_list.c

void list_entry_destructor(void *ptr)
{
	zend_rsrc_list_entry *le = (zend_rsrc_list_entry *) ptr;
	zend_rsrc_list_dtors_entry *ld;
	
	if (zend_hash_index_find(&list_destructors, le->type,(void **) &ld)==SUCCESS) {
		switch (ld->type) {
			case ZEND_RESOURCE_LIST_TYPE_STD:
				if (ld->list_dtor) {
					(ld->list_dtor)(le->ptr);
				}
				break;
			case ZEND_RESOURCE_LIST_TYPE_EX:
				if (ld->list_dtor_ex) {
					ld->list_dtor_ex(le); /******** CRASH HERE ********/
				}
				break;
			EMPTY_SWITCH_DEFAULT_CASE()
		}
	} else {
		zend_error(E_WARNING,"Unknown list entry type in request shutdown 

(%d)",le->type);
	}
}

----------------- snippet zend_list.c END

When I dug a bit deeper I saw the following happening:
ld->list_dtor_ex had the follwing values on two consecutive calls:
First: _close_odbc_conn(_zend_rsrc_list_entry *)
Second: _free_odbc_result(_zend_rsrc_list_entry *) 
----> after that some ODBC32 functions are called then CRASH

BUT on another page that didn't cause PHP to crash and utilized odbc, it had the following values on three consecutive calls:
First: _free_odbc_result(_zend_rsrc_list_entry *)
Second: _file_fopen_dtor(_zend_rsrc_list_entry *)
Third: _close_odbc_conn(_zend_rsrc_list_entry *)



I'm no expert for the PHP source (was the first time I saw it, actually) but I imagine the crash has something to do with the wrong order of the calls, if it's not something with the odbc drivers (Jet...). Especially, notice that, when you change the position of the two lines that free the odbc result and close the connection, PHP behaves normally (see test2.php).

hope that helps,

kai

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-04 12:50 UTC] kai dot brockmann at 3und20 dot net
First, I forgot to mention that the crash happens in release as well as in debug version.
Second, I discovered bug No. 12620 and tried to compile with ZEND_DISABLE_MEMORY_CACHE set to 1. Result: still crashes in debug version.

 [2001-09-04 12:52 UTC] kai dot brockmann at 3und20 dot net
First, I forgot to mention that the crash happens in release as well as in debug version.
Second, I discovered bug No. 12620 and tried to compile with ZEND_DISABLE_MEMORY_CACHE set to 1. Result: still crashes in debug version.

 [2002-02-04 02:25 UTC] yohgaki@php.net
Could you update PHP version that you've tested most recently?
 [2002-03-06 00:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC