Bug #69752 [NEW]: PDOStatement::execute() leaks memory with DML Statements when closeCuror() is u
| From: | phofstetter at sensational dot ch | Date: | Wed, 03 Jun 2015 11:59:34 +0000 |
| Subject: | Bug #69752 [NEW]: PDOStatement::execute() leaks memory with DML Statements when closeCuror() is u | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193086@lists.php.net to get a copy of this message | ||
From: phofstetter at sensational dot ch
Operating system: MacOS X and Linux
PHP version: 5.6.9
Package: PDO PgSQL
Bug Type: Bug
Bug description:PDOStatement::execute() leaks memory with DML Statements when closeCuror() is u
Description:
------------
using PDO PGSql, when calling closeCursor() on a statement before
re-using it in a future execute(), some amount of memory is leaked every
time the statement is executed.
This only happens on DML statements (insert or update) and it only
happens when closeCursor() is being called.
Test script:
---------------
<?php
printf("I'm pid %d\n", getmypid());
$pdo = new PDO('pgsql:dbname=somedb;user=someuser;host=127.0.0.1');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->exec('discard all');
$pdo->exec("set client_encoding to 'utf-8'");
$pdo->beginTransaction();
$pdo->exec("
create table foo (
id bigserial not null primary key,
field1 text not null,
field2 text not null,
field3 text not null,
field4 int4 not null
)
");
// leaks
$stmt = $pdo->prepare("insert into foo (field1, field2, field3, field4)
values (:field1, :field2, :field3, :field4)");
// also leaks
//$stmt = $pdo->prepare("update foo set field1 = :field1, field2 =
:field2, field3 = :field3 where field4 = :field4");
// doesn't leak
//$stmt = $pdo->prepare("select * from foo where field1 = :field1 and
field2 = :field2 and field3 = :field3 and field4 = :field4");
$max = 10000;
for($i = 0; $i < $max; $i++) {
$data = array(
'field1' => "field1: $i",
'field2' => "field2: $i",
'field3' => "field3: $i",
'field4' => $i
);
$stmt->execute($data);
$stmt->closeCursor(); // leak goes away if closeCursor() is removed
printf("\r%d", memory_get_usage(true)/1024);
}
$pdo->rollBack();
Expected result:
----------------
printed memory usage should stay constant.
Actual result:
--------------
printed memory usage is continuously increasing.
--
Edit bug report at https://bugs.php.net/bug.php?id=69752&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69752&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69752&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69752&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69752&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69752&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69752&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69752&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69752&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69752&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69752&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69752&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69752&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69752&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69752&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69752&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69752&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69752&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69752&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69752&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69752&r=mysqlcfg