php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76488 Memory leak when fetching a BLOB field
Submitted: 2018-06-17 13:17 UTC Modified: 2018-07-22 11:50 UTC
Votes:4
Avg. Score:4.0 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: sim-mail at list dot ru Assigned: nikic (profile)
Status: Closed Package: PDO Firebird
PHP Version: 7.2.6 OS: Any OS
Private report: No CVE-ID: None
 [2018-06-17 13:17 UTC] sim-mail at list dot ru
Description:
------------
Affects Versions: 7.0.x, 7.1.x, 7.2.x

Memory leak when fetching a BLOB field


Test script:
---------------
<?php

try {
    $dbh = new \PDO('firebird:dbname=localhost:employee', 'SYSDBA', 'masterkey');
    $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
    $dbh->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
    $dbh->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_NATURAL);

$sql = '
with recursive r(n) as (
  select 1 from rdb$database
  union all
  select n+1 from r where n < 1000
)
select n,
       cast(lpad(\'A\', 8000, \'A\') as BLOB sub_type TEXT) as SRC
from r 
';

    echo "First used: " . memory_get_usage(true) . "<br>";
  
    for ($i = 0; $i < 20; $i++) {
        $sth = $dbh->prepare($sql);
        $sth->execute();          
        $rows = $sth->fetchAll();
	    unset($rows);
	    unset($sth);
        echo "$i itteration used: " . memory_get_usage(true) . "<br>";
    }
    unset($dbh);
    echo "Last used: " . memory_get_usage(true) . "<br>";
}
catch(Exception $e) {
	var_dump($e);
}

Expected result:
----------------
First used: 2097152
0 itteration used: 2097152
1 itteration used: 2097152
2 itteration used: 2097152
3 itteration used: 2097152
4 itteration used: 2097152
5 itteration used: 2097152
6 itteration used: 2097152
7 itteration used: 2097152
8 itteration used: 2097152
9 itteration used: 2097152
10 itteration used: 2097152
11 itteration used: 2097152
12 itteration used: 2097152
13 itteration used: 2097152
14 itteration used: 2097152
15 itteration used: 2097152
16 itteration used: 2097152
17 itteration used: 2097152
18 itteration used: 2097152
19 itteration used: 2097152
Last used: 2097152

Actual result:
--------------
First used: 2097152
0 itteration used: 18874368
1 itteration used: 27262976
2 itteration used: 35651584
3 itteration used: 44040192
4 itteration used: 50331648
5 itteration used: 58720256
6 itteration used: 67108864
7 itteration used: 75497472
8 itteration used: 83886080
9 itteration used: 92274688
10 itteration used: 100663296
11 itteration used: 109051904
12 itteration used: 117440512
13 itteration used: 125829120
14 itteration used: 134217728

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in E:\php_test\test.php on line 25

Patches

firebird_statement.diff (last revision 2018-06-17 13:18 UTC by sim-mail at list dot ru)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-06 14:10 UTC] ab@php.net
Automatic comment on behalf of sim-mail@list.ru
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3847a6fcb63c362548e9434b195232f2dcf7a6c7
Log: Fix bug #76488 Memory leak when fetching a BLOB field
 [2018-07-06 14:10 UTC] ab@php.net
-Status: Open +Status: Closed
 [2018-07-22 11:31 UTC] nikic@php.net
-Status: Closed +Status: Re-Opened
 [2018-07-22 11:31 UTC] nikic@php.net
Reopened to track backports.
 [2018-07-22 11:50 UTC] nikic@php.net
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: nikic
 [2018-07-22 11:50 UTC] nikic@php.net
ab pointed out that is is already in 7.1/7.2, I got confused by the (apparently still broken) GH branch listing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 15:01:29 2024 UTC