com php-src: Fix bug #76488 Memory leak when fetching a BLOB field: ext/pdo_firebird/firebird_statement.c ext/pdo_firebir d/tests/bug_76488.phpt
| From: | Anatol Belski | Date: | Fri, 06 Jul 2018 14:07:28 +0000 |
| Subject: | com php-src: Fix bug #76488 Memory leak when fetching a BLOB field: ext/pdo_firebird/firebird_statement.c ext/pdo_firebir d/tests/bug_76488.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-102451@lists.php.net to get a copy of this message | ||
Commit: 3847a6fcb63c362548e9434b195232f2dcf7a6c7
Author: sim1984 <sim-mail@list.ru> Mon, 25 Jun 2018 21:35:51 +0300
Committer: Anatol Belski <ab@php.net> Fri, 6 Jul 2018 16:07:28 +0200
Parents: 137f22ad3685b20e5717af4dad49d1238076f2a8
Branches: PHP-7.1 PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3847a6fcb63c362548e9434b195232f2dcf7a6c7
Log:
Fix bug #76488 Memory leak when fetching a BLOB field
Add a phpt test
Bugs:
https://bugs.php.net/76488
Changed paths:
M ext/pdo_firebird/firebird_statement..c
A ext/pdo_firebird/tests/bug_76488.phpt
Diff:
diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c
index bfe2dd7..46dc107 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 0000000..dba6734
--- /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