summaryrefslogtreecommitdiff
path: root/ext/pdo_firebird
diff options
context:
space:
mode:
authorsim1984 <sim-mail@list.ru>2018-06-25 21:35:51 +0300
committerAnatol Belski <ab@php.net>2018-07-06 16:07:28 +0200
commit3847a6fcb63c362548e9434b195232f2dcf7a6c7 (patch)
treeca6563a16baf607b48a0fab9b8b3151b28f154ed /ext/pdo_firebird
parent137f22ad3685b20e5717af4dad49d1238076f2a8 (diff)
downloadphp-git-3847a6fcb63c362548e9434b195232f2dcf7a6c7.tar.gz
Fix bug #76488 Memory leak when fetching a BLOB field
Add a phpt test
Diffstat (limited to 'ext/pdo_firebird')
-rw-r--r--ext/pdo_firebird/firebird_statement.c2
-rw-r--r--ext/pdo_firebird/tests/bug_76488.phpt32
2 files changed, 33 insertions, 1 deletions
diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c
index bfe2dd717d..46dc10760a 100644
--- a/ext/pdo_firebird/firebird_statement.c
+++ b/ext/pdo_firebird/firebird_statement.c
@@ -294,7 +294,7 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, char **ptr, /* {{{ *
unsigned short seg_len;
ISC_STATUS stat;
- *ptr = S->fetch_buf[colno] = erealloc(*ptr, *len+1);
+ *ptr = S->fetch_buf[colno] = erealloc(S->fetch_buf[colno], *len+1);
for (cur_len = stat = 0; (!stat || stat == isc_segment) && cur_len < *len; cur_len += seg_len) {
diff --git a/ext/pdo_firebird/tests/bug_76488.phpt b/ext/pdo_firebird/tests/bug_76488.phpt
new file mode 100644
index 0000000000..dba6734c28
--- /dev/null
+++ b/ext/pdo_firebird/tests/bug_76488.phpt
@@ -0,0 +1,32 @@
+--TEST--
+PDO_Firebird: Bug #76488 Memory leak when fetching a BLOB field
+--SKIPIF--
+<?php if (!extension_loaded('interbase') || !extension_loaded('pdo_firebird')) die('skip'); ?>
+--FILE--
+<?php
+require 'testdb.inc';
+$dbh = new PDO('firebird:dbname='.$test_base, $user, $password) or die;
+
+$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
+';
+
+ for ($i = 0; $i < 10; $i++) {
+ $sth = $dbh->prepare($sql);
+ $sth->execute();
+ $rows = $sth->fetchAll();
+ unset($rows);
+ unset($sth);
+ }
+ unset($dbh);
+ echo "OK";
+?>
+--EXPECT--
+OK \ No newline at end of file