From: gavin at ipalsoftware dot com
Operating system: all
PHP version: 4.3.6
PHP Bug Type: MySQL related
Bug description: php_mysql_set_default_link leaks ref
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);
}
--
Edit bug report at http://bugs.php.net/?id=28627&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28627&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28627&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28627&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28627&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28627&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28627&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28627&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28627&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28627&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28627&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28627&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28627&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28627&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28627&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28627&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28627&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28627&r=float