Bug #75838 [NEW]: Memory leak in pg_escape_bytea()
| From: | ard_1 at mail dot ru | Date: | Wed, 17 Jan 2018 22:58:09 +0000 |
| Subject: | Bug #75838 [NEW]: Memory leak in pg_escape_bytea() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213596@lists.php.net to get a copy of this message | ||
From: ard_1 at mail dot ru
Operating system: Unix
PHP version: 7.0.27
Package: PostgreSQL related
Bug Type: Bug
Bug description:Memory leak in pg_escape_bytea()
Description:
------------
There is a memory leak in pg_escape_bytea() function due to a missing
call to PQfreemem().
This issue was first introduced with the following commit:
https://github.com/php/php-src/commit/1ff7c7b9a31bd3242b06436740322f7246a708f0
so all 7.x are affected.
Test script:
---------------
<?php
define('LN', "\n");
// Big file ~50Mb
$messData = file_get_contents('./bigfile');
for($i=0; $i<3; $i++) {
$db = pg_connect('host=pgserver port=5432 dbname=testdb user=dbuser
password=dbuserpass connect_timeout=5');
echo "$i Before: ".memStat().LN;
$escData = pg_escape_bytea($db, $messData);
echo "$i Esc: ".memStat().LN;
unset ($escData);
pg_close($db);
echo "$i Clear: ".memStat().LN.LN;
}
echo 'End: '.memStat().LN;
sleep (20);
function memStat() {
return round(memory_get_usage()/1024/1024, 2).' Mb';
}
?>
Actual result:
--------------
Though memory usage reported by memStat() stays the same, the memory
usage reported by "top" or "ps" tools will grow.
Also the issue can be reproduced by running the test script with php-fpm
and monitoring the OS memory usage.
The patch for this issue should be trivial - one can invoke
PQfreemem(to) after
RETVAL_STRINGL(to, to_len-1); /* to_len includes addtional '\0' */
in ext/pgsql/pgsql.c or call efree(to) as it being done for
pg_unescape_bytea() function.
--
Edit bug report at https://bugs.php.net/bug.php?id=75838&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75838&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75838&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75838&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75838&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75838&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75838&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75838&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75838&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75838&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75838&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75838&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75838&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75838&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75838&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75838&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75838&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75838&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75838&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75838&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75838&r=mysqlcfg