Bug #75838 [Opn->Csd]: Memory leak in pg_escape_bytea()
| From: | laruence@php.net | Date: | Thu, 18 Jan 2018 02:54:27 +0000 |
| Subject: | Bug #75838 [Opn->Csd]: Memory leak in pg_escape_bytea() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213599@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75838&edit=1
ID: 75838
Updated by: laruence@php.net
Reported by: ard_1 at mail dot ru
Summary: Memory leak in pg_escape_bytea()
-Status: Open
+Status: Closed
Type: Bug
Package: PostgreSQL related
Operating System: Unix
PHP Version: 7.0.27
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=fb205020ce2dd97d777e09d2debf38a01075d370
Log: Fixed #75838 (Memory leak in pg_escape_bytea())
Previous Comments:
------------------------------------------------------------------------
[2018-01-17 22:58:07] ard_1 at mail dot ru
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 this bug report at https://bugs.php.net/bug.php?id=75838&edit=1