Bug #18494: DB::query leaks memory
| From: | sam at ananova dot com | Date: | Tue, 23 Jul 2002 15:13:08 +0000 |
| Subject: | Bug #18494: DB::query leaks memory | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-7922@lists.php.net to get a copy of this message | ||
From: sam@ananova.com
Operating system: linux redhat 7.3 up2date-ed
PHP version: 4.2.0
PHP Bug Type: PEAR related
Bug description: DB::query leaks memory
$result=$this->db->query($sql,$values);
makes use of "prepare" internally and doesn't free the results.
e.g., the following script, does one query 5 times and annother time with
different values, yet when done, diagnose() prints out that 6 lots of
prepare_tokens, prepare_types, prepare_queries were stored in the db
object!
I reckon at least they should have been destroyed when the results were
destroyed (if no results, then right away!).
<?php
include_once("DB.php");
$_db=array(
'phptype' => "pgsql",
'hostspec' => "localhost",
'database' => "*****",
'username' => "*******",
'protocol' => "unix",
'password' => "***********");
$db=DB::connect($_db);
if (DB::isError($db)) {
die("Can't connect");
}
$sql="select ?";
QUERY($db,$sql,array(1));
QUERY($db,$sql,array(1));
QUERY($db,$sql,array(1));
QUERY($db,$sql,array(1));
QUERY($db,$sql,array(1));
QUERY($db,$sql,array(2));
var_dump($db);
diagnose($db);
function diagnose(&$db) {
foreach($db as $key=>$val) if (eregi('^prepare',$key) && is_array($val))
{
print count($val). " of $key\n";
}
}
function QUERY(&$db,$sql,$array) {
$result=$db->query($sql,array(1));
if (DB::isError($result)) {
die ("Dead: ".$result->userinfo);
}
$numRows=$result->numRows();
if ($numRows>1) die ("Too many matches for $query,");
if ($numRows) {
$data=$result->fetchRow(DB_FETCHMODE_ASSOC);
}
if (is_object($result)) $result->free();
return $data;
}
?>
--
Edit bug report at http://bugs.php.net/?id=18494&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18494&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18494&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18494&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18494&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18494&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18494&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18494&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18494&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18494&r=globals