php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44206 Cursor leak with REF CURSORS
Submitted: 2008-02-21 19:29 UTC Modified: 2008-02-26 00:24 UTC
From: christopher dot jones at oracle dot com Assigned:
Status: Closed Package: OCI8 related
PHP Version: 5.2.5 OS: n/a
Private report: No CVE-ID: None
 [2008-02-21 19:29 UTC] christopher dot jones at oracle dot com
Description:
------------
When more than one REF CURSOR is returned in a query, ORA-1000 occurs after some iterations.
Haneef investigated and says:
  "The refcount of the parent statement is incremented by the ref
  cursors in php_oci_define_callback and is not decremented. The
  incrementing is necessary as the parent statement needs to be around
  while fetching the data from the ref cursor. The fix is to decrement
  the refcount of the parent statement before ref cursor is freed."
The fix is being tested.

Reproduce code:
---------------
<?php
$c = oci_connect('hr', 'hrpwd', '//localhost/XE');
for ($x = 0; $x < 400; $x++) {
// more than one CURSOR column causes the problem.
    $sql = "select cursor(select $x from dual) a,
                   cursor(select $x from dual) b
                   from dual";
    
    $sth = oci_parse($c, $sql);
    $r = oci_execute($sth);
    if (!$r) {
        echo "Exiting $x\n"; exit;
    }
    while ($row = oci_fetch_array($sth, OCI_ASSOC)) {
        if ($row) {
            foreach ($row as $k => $v) {
                if (is_resource($v) &&
                    get_resource_type($v) == "oci8 statement") {
                    oci_execute($v);
                    oci_fetch_all($v, $row[$k], 0, -1, OCI_ASSOC);
                    oci_free_statement($v);
                }
            }
        }
        echo $x, "\n";
    }
    oci_free_statement($sth);
}
print "Completed $x\n";
oci_close($c);
?>


Expected result:
----------------
...
398
399
Completed 400

Actual result:
--------------
...
295
296
PHP Warning:  oci_execute(): ORA-00604: error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded in test.php on line 10
Exiting 297

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-26 00:24 UTC] sixd@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.

+------------------------------
| Fix has been merged to 5.2.6, 5.3 and 6.
| Thanks go to Haneef.
+------------------------------

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC