|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48754 mysql_close() crash php when no handle specified
Submitted: 2009-07-01 12:30 UTC Modified: 2009-09-18 10:50 UTC
Avg. Score:4.5 ± 0.9
Reproduced:49 of 50 (98.0%)
Same Version:46 (93.9%)
Same OS:34 (69.4%)
From: busia at tiscali dot it Assigned: mysql
Status: Closed Package: MySQL related
PHP Version: 5.3.0 (as of 21-07-2008) OS: *
Private report: No CVE-ID:
 [2009-07-01 12:30 UTC] busia at tiscali dot it


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-01 18:04 UTC] sjoerd-php at linuxonly dot nl
Thank you for your bug report.

I have a couple of questions regarding your bug report:
1. Is the sleep(2) needed to reproduce the bug?
2. Does the database connection succeed? (i.e. what is the return value of mysql_connect?)
 [2009-07-01 21:59 UTC] busia at tiscali dot it
1) The sleep function is not needed
2) The connection is successfull

An other information: if I save in $a the mysql_connect return value and pass it to mysql_close php doesn't crash. In othe words this script works well:
$a=mysql_connect('', 'root', 'root');

This instead crashes php:
mysql_connect('', 'root', 'root');
 [2009-07-02 13:05 UTC]
This one is funny. It may have existed since more than one year now and nobody has ever found it.
 [2009-07-02 16:45 UTC]
Really a great one.

The bug exists since 21-07-2008. That is 11 months and 1 week ago. Sometimes I which users would try non-GA versions just in case test suites don't catch issues...

This is when the bug was introduced:

mysql_link points to NULL and that's causing a crash. 

Possible workaround (as suggested by Johannes):

nixnutz@linux-en61:~/src/login/php5> cvs diff ext/mysql/tests/
cvs diff: Diffing .
cvs diff: Diffing ext
cvs diff: Diffing ext/mysql
cvs diff: Diffing ext/mysql/tests
nixnutz@linux-en61:~/src/login/php5> cvs diff ext/mysql/
cvs diff: Diffing ext/mysql
Index: ext/mysql/php_mysql.c
RCS file: /repository/php-src/ext/mysql/php_mysql.c,v
retrieving revision
diff -r1. php_mysql.c
>       mysqlnd_end_psession(link->conn);
> #endif
<       {
<               int tmp;
<               if ((mysql = zend_list_find(Z_RESVAL_P(mysql_link), &tmp)) && tmp == le_plink) {
<                       mysqlnd_end_psession(mysql->conn);
<               }
<       }
< #endif
<       if (mysql_link) { /* explicit resource number */
>       if (mysql_link) {
cvs diff: Diffing ext/mysql/tests

Someone may want to review that.
 [2009-07-07 14:47 UTC] xektrum at gmail dot com
I can confirm this, I'm having the same issue with php 5.3 and apache2 when calling mysql_close without a mysql_link as parameter.

Reproduce code: 

mysql_close(); // win32 uncaught exception catched by MSVS


Workaround/not crashing:
$link = mysql_connect('localhost','root','password');

Exception :
Not handled Exception in 0x006e2072 in httpd.exe: 0xC0000005:
Access violation when reading location 0x00000000.

Note : The Exception has been translated so it is not literal
 [2009-07-14 01:50 UTC] sujoe_2006 at 163 dot com
my development evioronment is 
   windows xp sp2
   apache 2.2
   php 5.3.0
   mysql 5.1.36

I write some code in test.php
   $conn = mysql_connect('ip','user','password');
then ,I Will be catched a error by apache 2.2,it is:
0x006e2072 in httpd.exe: 0xC0000005:
Access violation when reading location 0x00000000.

but when check the mysql_close function like this for test.php
   $conn = mysql_connect('ip','user','password');
it will work no any error.
so ,i want to know its reason of the mysql_close(),please mail to me
 [2009-07-16 14:34 UTC] guillermog at tricuspide dot com
Still in the release, I really think lot's of people are having the same 
problem with their sctripts!!

I filled a bug report hours ago to later accidentally find that it was a 
very simple problem. Once I found the problem I looked for mysql_close 
and version 5.3 to find this bug report.

Uff finnally after the whole day!!!


 [2009-08-26 05:13 UTC] jfb at zer7 dot com
I get this as well. I had avoided upgrading my ancient PHP code (some of it was from PHP4); turns out it being that ancient also means it uses old patterns, like not using handles. :)

Likely that newer code will not encounter this, so it'll be folks upgrading slowly and cautiously.
 [2009-08-28 23:27 UTC] empacc100 at seznam dot cz
WinXP SP3, PHP 5.3.0 VC9 TS, Apache 2.2.13 (apachelounge) + mod_fcgid 2.2b, MySQL 5.1.37 == same bug (php-cgi.exe crash)

* php-cgi.exe OK
$a=mysql_connect('', 'root', 'fdgdfgd'));

* php-cgi.exe CRASH
mysql_connect('', 'root', 'fdgdfgd'));
 [2009-09-09 05:21 UTC] louis at steelbytes dot com
repro on 5.3.0 on Win2003 using php.exe in command shell.  didn't have this problem with 5.2.10
 [2009-09-18 10:46 UTC]
Automatic comment from SVN on behalf of andrey
Log: Fix for bug#48754 mysql_close() crash php when no handle specified
 [2009-09-18 10:49 UTC]
Automatic comment from SVN on behalf of andrey
Log: MFH:Fix for bug#48754 mysql_close() crash php when no handle specified
 [2009-09-18 10:50 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fix should be part of 5.3.1
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 21:01:32 2015 UTC