php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23103 Memory Leak in DB/common.php
Submitted: 2003-04-07 17:36 UTC Modified: 2003-06-11 12:08 UTC
From: zukerman at math-hat dot com Assigned: ssb (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zukerman at math-hat dot com
New email:
PHP Version: OS:

 

 [2003-04-07 17:36 UTC] zukerman at math-hat dot com
It looks like when DB_common::getOne() or DB_common::getRow() is called, and no results are returned, the DB_Result object is never free()ed.  With pgsql this means that the row and num_rows arrays never get cleared.

I came across this when my PHP scripts died with out-of-memory exceptions.

This doesn't yet seem to be fixed in CVS.  I think the simple fix is to move the lines that free $res above the test of $err:

--- common.php.orig	2003-04-06 11:08:53.000000000 -0400
+++ common.php	2003-04-06 11:08:34.000000000 -0400
@@ -700,16 +700,16 @@
         }
 
         $err = $res->fetchInto($row, DB_FETCHMODE_ORDERED);
-        if ($err !== DB_OK) {
-            return $err;
-        }
 
         $res->free();
-
         if (isset($sth)) {
             $this->freeResult($sth);
         }
 
+        if ($err !== DB_OK) {
+            return $err;
+        }
+
         return $row[0];
     }
 
@@ -764,15 +764,15 @@
 
         $err = $res->fetchInto($row, $fetchmode);
 
-        if ($err !== DB_OK) {
-            return $err;
-        }
         $res->free();
-
         if (isset($sth)) {
             $this->freeResult($sth);
         }
 
+        if ($err !== DB_OK) {
+            return $err;
+        }
+
         return $row;
     }
 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-28 03:57 UTC] arnaud@php.net
changing status
 [2003-05-04 12:26 UTC] lsmith@php.net
This is also related to http://bugs.php.net/bug.php?id=18494
 [2003-06-11 12:08 UTC] cox@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, 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/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC