php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40121 DBLIB driver wont free statements
Submitted: 2007-01-13 18:19 UTC Modified: 2009-05-03 01:00 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:1 (16.7%)
From: spheroid@php.net Assigned: fmk (profile)
Status: No Feedback Package: PDO related
PHP Version: 5.2.5 OS: Mac OS X 10.4.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: spheroid@php.net
New email:
PHP Version: OS:

 

 [2007-01-13 18:19 UTC] spheroid@php.net
Description:
------------
As stated on the summary, PDO DBLIB driver wont free memory 
allocated to statements (or the resultset, not sure). Same 
code done with ext/mssql functions works, though.

Reproduce code:
---------------
$db = new PDO('dblib:host=hostname;dbname=database', 'user', 'password');
$query = 'SELECT GETDATE()'; // NOW() on mysql

for ($i = 0; $i < 10; $i++) {
    $stmt = $db->query($query); // new statement
    $stmt->fetch();             // actual data
    $stmt->fetch();             // false; end of resultset
    $stmt->closeCursor();       // this should at least free it, right?
    $stmt = null;               // being paranoid here

    echo memory_get_usage() . "\n";
}

Expected result:
----------------
54152
54152
54152
54152
54152
54152
54152
54152
54152
54152

Actual result:
--------------
54152
54252
54292
54332
54372
54412
54452
54492
54532
54572

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-13 18:23 UTC] spheroid@php.net
Forgot to mention that it works perfectly with MySQL driver.
 [2007-01-14 16:57 UTC] iliaa@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.


 [2007-01-14 21:50 UTC] spheroid@php.net
I couldn't get it to compile, so I corrected the mysql -> 
dblib, not sure whether this was the intention though. I 
don't have enough karma, so the patch is below:

RCS file: /repository/php-src/ext/pdo_dblib/dblib_stmt.c,v
retrieving revision 1.6.2.2.2.3
diff -u -r1.6.2.2.2.3 dblib_stmt.c
--- dblib_stmt.c        14 Jan 2007 16:57:50 -0000      
1.6.2.2.2.3
+++ dblib_stmt.c        14 Jan 2007 21:43:35 -0000
@@ -250,9 +250,9 @@
        return 1;
 }
 
-static int dblib_mysql_stmt_cursor_closer(pdo_stmt_t *stmt 
TSRMLS_DC)
+static int pdo_dblib_stmt_cursor_closer(pdo_stmt_t *stmt 
TSRMLS_DC)
 {
-       pdo_dblib_stmt *S = (pdo_mysql_stmt*)stmt-
>driver_data;
+       pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt-
>driver_data;
 
        if (S->rows) {
                free_rows(S TSRMLS_CC);
@@ -273,6 +273,6 @@
        NULL, /* get attr */
        NULL, /* meta */
        NULL, /* nextrow */
-       dblib_mysql_stmt_cursor_closer
+       pdo_dblib_stmt_cursor_closer
 };


However, it doesn't fix the problem. See, gdb breaks fine on 
pdo_dblib_stmt_dtor on each iteration and stepping it shows 
that it even attempts to free stuff. So I guess the error 
isn't here?

After running gdb with patch above it does close the cursor 
on each iteration, but it's not still affecting the 
increasing memory usage.
 [2007-01-15 07:07 UTC] spheroid@php.net
After playing around with GDB I noticed that the S->cols is 
being allocated on different memory block each time. S and S-
>rows stay in the same place, though. I suppose this is due 
the different methods used to allocate memory, but I just 
don't have enough clue to fix it.
 [2007-01-15 12:11 UTC] spheroid@php.net
And more issues :-)

That previous example was done with just one row in the 
resultset, but after I tried to return more rows, I found 
something disturbing:

Code:

$db = new PDO('dblib:host=hostname;dbname=database', 
'username', 'password');
$query = 'select top 10 * from table';
$stmt = $db->prepare($query);

for ($i = 0; $i < 10; $i++) {
    $stmt->execute();
    $stmt->fetchAll();
    $stmt->closeCursor();

    echo memory_get_usage() . "\n";
}

Output:

172240
240044
307824
375632
443464
511288
579064
646932
714776
782576
 [2008-04-24 18:23 UTC] eric dot johney at sellingsource dot com
This is still a problem for me in 5.2.5 using the PDO DBLIB driver. Mysql and mssql_* functions work fine on the same query.
 [2009-04-25 14:42 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2013-10-23 19:36 UTC] b808054 at drdrb dot com
I have the same problem with version 5.3.10
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC