php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51796 Memory leak when executing SQL "EXEC" statements
Submitted: 2010-05-11 17:48 UTC Modified: 2013-02-18 00:34 UTC
From: J dot Antonio at jaruz dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.3.2 OS: Ubuntu 10.04 LTS
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-05-11 17:48 UTC] J dot Antonio at jaruz dot com
Description:
------------
On Linux, using PHP 5.3.2-1ubuntu4 with Suhosin-Patch (cli) and FreeTDS 0.82-6build1 (it's a vanilla lucid install, fully up to date):

When executing stored procedures using the "EXEC" SQL statement, both PDOStatement->execute as well as PDO::query seem to have a memory leak. We found this while executing a stored procedure within a loop: memory usage just kept increasing till the memory limit was reached. Unsetting/nullyfing variables does not help.

The leak is not present (memory usage stays perfectly constant) when using a "SELECT" SQL statement (which returns the exact same results as the stored procedure).

I have a feeling PDO is maybe only clearing the memory when it deals with a "SELECT" statement, and it misses the fact that data can also come back through "EXEC" statements?

This bug might be slightly related to bug 50755.


Test script:
---------------
// $polyItemArray is populated with a list of 300 IDs (integers).
// We loop through the array, and execute a stored procedure during each iteration:
foreach( $polyItemArray as $polyItemKey => $polyItem) {
	echo date('H:i:s') . ' | Processing: ' . $polyItem['sgp_id'];

	$dbh->query('EXEC proc_map_get_sgp_polygons ' . $polyItem['sgp_id'], PDO::FETCH_ASSOC);

/*
        // Alternate way of calling the procedure using PDOStatement; same leak is present:
	$stmt = $dbh->prepare($sql);
	$stmt->setFetchMode(PDO::FETCH_ASSOC);
	$stmt->execute( array($polyItem['sgp_id']) );
	$stmt->closeCursor();
	unset($stmt);
*/

	unset($polyItemKey);
	unset($polyItem);
	echo ' memory usage: ' . memory_get_usage(). ' bytes'. PHP_EOL;
}

// When running the script, memory usage just keeps increasing.

Expected result:
----------------
I would expect the memory usage of the script to stay constant.

Actual result:
--------------
Memory usage just keeps increasing.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-11 17:50 UTC] J dot Antonio at jaruz dot com
I forgot to mention this is using PDO_DBLIB.
 [2010-05-12 18:41 UTC] sixd@php.net
For reference, there are some pdo_dblib patches mentioned in 
http://bugs.php.net/50755
 [2010-05-12 18:43 UTC] sixd@php.net
-Status: Open +Status: Feedback
 [2010-05-12 18:43 UTC] sixd@php.net
Try the patches and see if your bug is a duplicate.
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 02:01:28 2024 UTC