php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78525 Memory leak in pdo when reusing native prepared statements
Submitted: 2019-09-11 10:36 UTC Modified: 2019-09-12 13:59 UTC
From: victoria at sharksmedia dot dk Assigned: nikic (profile)
Status: Closed Package: PDO MySQL
PHP Version: 7.3.9 OS: CentOS 7.6.1810
Private report: No CVE-ID: None
 [2019-09-11 10:36 UTC] victoria at sharksmedia dot dk
Description:
------------
If a native prepared statement is reused, it will leak memory on each reuse.
If the statement is prepared each time, there is no memory leak.

All versions of PHP 7.2 works, and all versions of PHP 7.3 leaks memory.

Versions:
Percona MySQL 5.7 & 8.0
PHP 7.3.x
Mysqlnd: mysqlnd 5.0.12-dev

The call to closeCursor() doesn't change anything.

Test script:
---------------
$pdo = new \PDO('mysql:host=<host>;dbname=<dbname>', 'user', 'password');

$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);

$stmt = $pdo->prepare('SELECT field FROM table LIMIT 100');

for($i=0;$i<250000;$i++)
{
	$stmt->execute();
	
	$stmt->fetchAll();
	
	//$stmt->closeCursor();
	
	if($i%1000 === 0) print memory_get_usage()."\r\n";
}

Expected result:
----------------
PHP 7.2.22:
446824
446856
446856
446856
446856
446856
446856
446856
446856
446856
446856
446856
446856
446856
446856

Actual result:
--------------
PHP 7.3.9:
479176
970728
1445864
1937384
2428904
2920424
3411944
3903464
4378600
4870120
5361640
5853160
6344680
6836200
7327720

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-11 10:45 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2019-09-12 13:59 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2019-09-13 12:37 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=df982da5874856e3a4d6bbbefb8d3be97261a6cf
Log: Fix bug #78525
 [2019-09-13 12:37 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 22:01:29 2019 UTC