|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57145 Memory leak when db2_connect() fails
Submitted: 2006-07-18 23:02 UTC Modified: 2006-07-24 10:43 UTC
From: larry dot menard at rogers dot com Assigned: kraman (profile)
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.1.2 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2006-07-18 23:02 UTC] larry dot menard at rogers dot com
There seems to be a memory leak in the ibm_db2 package's "db2_connect()" API.  Every time a connect fails the memory usage increases by about 80Kb, and it never goes down again.  Memory usage does not increase if the "db2_connect()" calls are successful... it only increases if the "db2_connect()" calls fail.

I wrote a repro script (attached below) that does a number of "db2_connect()" attempts.  If you specify some parameter that makes the connect fail (e.g., an invalid db name) and monitor the "php" process's memory using "perfmon.exe" or "Task Manager", you'll see the footprint creep.

The same script can also be used to do a number of MS SQL Server "mssql_connect()" attempts.  It does not leak at all.

So I suspect the leak is in the "db2_connect()" API, not in PHP itself.

Note: I'm actually using PHP 5.1.4, but that version is not currently found in the selection box on this page.

Reproduce code:
URL to the test script:

Run it from a command prompt like:

php memory_test.php $sleeptime $iterations $rdbms $dbname $userid $password


php memory_test.php 1 20 DB2 mydb myuserid mypasswd

To make it use the SQL Server APIs:

php memory_test.php 1 20 DB2 mssql myuserid mypasswd

Expected result:
No increase in memory usage.

Actual result:
Memory usage increases by about 80Kb every time "db2_connect()" fails.  It does not increase if the MS SQL Server APIs are used.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-24 10:43 UTC] kraman at gmail dot com
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Jun 23 03:01:23 2021 UTC