|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28627 php_mysql_set_default_link leaks ref
Submitted: 2004-06-03 23:31 UTC Modified: 2004-06-04 15:49 UTC
From: gavin at ipalsoftware dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.3.6 OS: all
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: gavin at ipalsoftware dot com
New email:
PHP Version: OS:


 [2004-06-03 23:31 UTC] gavin at ipalsoftware dot com
In php_mysql.c:

/* {{{ php_mysql_set_default_link
static void php_mysql_set_default_link(int id TSRMLS_DC)
    MySG(default_link) = id;
/* }}} */

if MySG(default_link) is already set (!= -1), the above code needs to deref it before setting the default_link.  Otherwise a mysql_close down the road on the original default_link will not actually close the connection (it has too many references now).

Reproduce code:
A possible patch:

--- php-4.3.6.orig/ext/mysql/php_mysql.c        2004-06-03 16:08:29.124642476 -0500
+++ php-4.3.6/ext/mysql/php_mysql.c     2004-06-03 16:13:21.192405843 -0500
@@ -259,6 +259,9 @@
 static void php_mysql_set_default_link(int id TSRMLS_DC)
+       if (MySG(default_link)!=-1) {
+               zend_list_delete(MySG(default_link));
+       }
        MySG(default_link) = id;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-04 15:49 UTC]
This bug has been fixed in CVS.

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.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 03:01:30 2024 UTC