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