#25869 [NEW]: PostgeSQL Memory leaks with "prepare"d queries.
| From: | chris at statgen dot ncsu dot edu | Date: | Tue, 14 Oct 2003 17:52:08 +0000 |
| Subject: | #25869 [NEW]: PostgeSQL Memory leaks with "prepare"d queries. | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-22690@lists.php.net to get a copy of this message | ||
From: chris at statgen dot ncsu dot edu
Operating system: Windows XP
PHP version: 4.3.2
PHP Bug Type: PEAR related
Bug description: PostgeSQL Memory leaks with "prepare"d queries.
Description:
------------
Issues with freeing Prepared Queries
------------------------------------
Here are some issues with freeing prepared queries in the
PostgreSQL implementation of DB.
1) If you use the query member in the form where you provide parameter
values as a second argument the query is prepared and executed but the
values produced by the prepare step are never freed. This leads to a
considerable memory leaks if the query member is used repeatedly in a
long-running process.
Here's a suggested fix for this one. In DB_common::query,
changes marked with "CSCS":
function &query($query, $params = array()) {
if (sizeof($params) > 0) {
$sth = $this->prepare($query);
if (DB::isError($sth)) {
return $sth;
}
// CSCS Prepared query should be freed
// CSCS return $this->execute($sth, $params);
$res = &$this->execute($sth, $params); // CSCS
$this->freeResult($sth); // CSCS
return $res; // CSCS
} else {
2) If you explicitly prepare a query there is no documented method defined
for freeing the prepared version. This is (generally) a smaller memory
leak since queries are usually prepared once and re-used often.
3) The freeResult member of DB_pgsql does not unset the query's entry in
the prepared_queries array. The entries in the prepare_tokens and
prepare_types arrays are freed.
Suggested fix in DB_pgsql::freeResult is to add one line...
unset($this->prepare_tokens[(int)$result]);
unset($this->prepare_types[(int)$result]);
unset($this->prepared_queries[(int)$result]); // CSCS
4) Not sure what effect this has but the prepare_tokens and prepare_types
arrays are defined in both the base DB_common class and the DB_pgsql
class. It seems like just having them in the DB_common class would be
enough.
Reproduce code:
---------------
Let me know if you would like some reproduce code.
--
Edit bug report at http://bugs.php.net/?id=25869&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25869&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25869&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=25869&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=25869&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=25869&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=25869&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=25869&r=support
Expected behavior: http://bugs.php.net/fix.php?id=25869&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=25869&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=25869&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=25869&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25869&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=25869&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=25869&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=25869&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25869&r=float