Skip to content

Commit 3847a6f

Browse files
sim1984weltling
authored andcommitted
Fix bug #76488 Memory leak when fetching a BLOB field
Add a phpt test
1 parent 137f22a commit 3847a6f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

ext/pdo_firebird/firebird_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, char **ptr, /* {{{ *
294294
unsigned short seg_len;
295295
ISC_STATUS stat;
296296

297-
*ptr = S->fetch_buf[colno] = erealloc(*ptr, *len+1);
297+
*ptr = S->fetch_buf[colno] = erealloc(S->fetch_buf[colno], *len+1);
298298

299299
for (cur_len = stat = 0; (!stat || stat == isc_segment) && cur_len < *len; cur_len += seg_len) {
300300

ext/pdo_firebird/tests/bug_76488.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
PDO_Firebird: Bug #76488 Memory leak when fetching a BLOB field
3+
--SKIPIF--
4+
<?php if (!extension_loaded('interbase') || !extension_loaded('pdo_firebird')) die('skip'); ?>
5+
--FILE--
6+
<?php
7+
require 'testdb.inc';
8+
$dbh = new PDO('firebird:dbname='.$test_base, $user, $password) or die;
9+
10+
$sql = '
11+
with recursive r(n) as (
12+
select 1 from rdb$database
13+
union all
14+
select n+1 from r where n < 1000
15+
)
16+
select n,
17+
cast(lpad(\'A\', 8000, \'A\') as BLOB sub_type TEXT) as SRC
18+
from r
19+
';
20+
21+
for ($i = 0; $i < 10; $i++) {
22+
$sth = $dbh->prepare($sql);
23+
$sth->execute();
24+
$rows = $sth->fetchAll();
25+
unset($rows);
26+
unset($sth);
27+
}
28+
unset($dbh);
29+
echo "OK";
30+
?>
31+
--EXPECT--
32+
OK

0 commit comments

Comments
 (0)