php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gavin at ipalsoftware dot com
New email:
PHP Version: OS:

 

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

/* {{{ php_mysql_set_default_link
 */
static void php_mysql_set_default_link(int id TSRMLS_DC)
{
    MySG(default_link) = id;
    zend_list_addref(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;
        zend_list_addref(id);
 }



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-04 15:49 UTC] iliaa@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC