1--TEST-- 2PDO PgSQL Bug #69752 (memory leak with closeCursor) 3--EXTENSIONS-- 4pdo_pgsql 5--SKIPIF-- 6<?php 7require __DIR__ . '/config.inc'; 8require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 9PDOTest::skip(); 10?> 11--FILE-- 12<?php 13require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 14$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt'); 15 16$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); 17 18$pdo->beginTransaction(); 19 20$pdo->exec(" 21 create table test69752 ( 22 id bigserial not null primary key, 23 field1 text not null, 24 field2 text not null, 25 field3 text not null, 26 field4 int4 not null 27 ) 28"); 29$stmt = $pdo->prepare("insert into test69752 (field1, field2, field3, field4) values (:field1, :field2, :field3, :field4)"); 30$max = 1000; 31$first_time_usage = null; 32 33for($i = 0; $i < $max; $i++) { 34 $data = array( 35 'field1' => "field1: $i", 36 'field2' => "field2: $i", 37 'field3' => "field3: $i", 38 'field4' => $i 39 ); 40 $stmt->execute($data); 41 $stmt->closeCursor(); 42 $usage = intval(floor(memory_get_usage() / 1024)); 43 44 if ($first_time_usage === null) $first_time_usage = $usage; 45 46 /* Use delta instead of direct comparison here */ 47 if (abs($first_time_usage - $usage) > 3){ 48 printf("Memory Leak Detected: %d != %d\n", $usage, $first_time_usage); 49 break; 50 } 51} 52$pdo->rollBack(); 53echo "done\n" 54?> 55--EXPECT-- 56done 57