Bug #75945 [NEW]: php leak memory when calling database function with 'RAISE NOTICE'
| From: | hnguyen at wyebot dot com | Date: | Fri, 09 Feb 2018 20:30:48 +0000 |
| Subject: | Bug #75945 [NEW]: php leak memory when calling database function with 'RAISE NOTICE' | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213902@lists.php.net to get a copy of this message | ||
From: hnguyen at wyebot dot com
Operating system: Ubuntu
PHP version: 7.2.2
Package: PostgreSQL related
Bug Type: Bug
Bug description:php leak memory when calling database function with 'RAISE NOTICE'
Description:
------------
Whenever php make a call to a postgresql database function with the
'RAISE NOTICE' statement in it then it leaks memory.
With the provided memTest.php script, if one run it on php 7.1 or 7.2,
there is a memory leak reported. Testing on php 7.0 leak memory but by
comparison it is much less. Please see below result.
Here is a test result with php 7.2:
# php -v
PHP 7.2.2-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Feb 1 2018
16:01:26) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.2-1+ubuntu16.04.1+deb.sury.org+1, Copyright
(c) 1999-2018, by Zend Technologies
# ./memTest.php
php-psql memory leak test for function with 'RAISE NOTICE'
After 1000 runs memory lost = 84920 bytes
Here is a test result with php 7.1:
# php -v
PHP 7.1.13-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jan 5 2018
13:26:45) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.13-1+ubuntu16.04.1+deb.sury.org+1, Copyright
(c) 1999-2017, by Zend Technologies
# ./memTest.php
php-psql memory leak test for function with 'RAISE NOTICE'
After 1000 runs memory lost = 84920 bytes
Here is a test result with php 7.0:
# php -v
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017,
by Zend Technologies
# ./memTest.php
php-psql memory leak test for function with 'RAISE NOTICE'
After 1000 runs memory lost = 112 bytes
Test script:
---------------
# memTest.php script
# usage: ./memTest.php
#!/usr/bin/env php
<?php
const NUM_RUNS = 1000;
function addNoticeFunction($con)
{
$query = "CREATE OR REPLACE FUNCTION test_function () RETURNS void
AS $$ BEGIN RAISE NOTICE 'Hellow World!'; END; $$ LANGUAGE plpgsql;"; //
this function will cause memory leak
//$query = "CREATE OR REPLACE FUNCTION test_function () RETURNS void
AS $$ BEGIN END; $$ LANGUAGE plpgsql;"; // this function will not cause
memory leak
$rs_client = pg_query($con, $query) or die("Cannot execute query:
$query\n");
if ($rs_client)
pg_free_result($rs_client);
}
function makeAQuery($con)
{
$query = "SELECT test_function()"; // lose 424 byte each run
$rs_client = pg_query($con, $query) or die("Cannot execute query:
$query\n");
if ($rs_client)
pg_free_result($rs_client);
}
function runQueryTests ($con)
{
$before = memory_get_usage();
for ($i = 0; $i < NUM_RUNS; ++$i) {
makeAQuery($con);
}
$after = memory_get_usage();
printf("After %d runs memory lost = %4d bytes\n", NUM_RUNS, $after -
$before);
}
print("php-psql memory leak test for function with 'RAISE NOTICE'\n");
$con = pg_pconnect("host=172.17.0.1 user=postgres") or go_die("Could not
connect to server\n");
addNoticeFunction($con);
runQueryTests($con);
pg_close($con);
?>
Expected result:
----------------
There should be 0 memory leak
Actual result:
--------------
There was 84920 bytes of memory leak after running the script
--
Edit bug report at https://bugs.php.net/bug.php?id=75945&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75945&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75945&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75945&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75945&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75945&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75945&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75945&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75945&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75945&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75945&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75945&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75945&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75945&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75945&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75945&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75945&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75945&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75945&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75945&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75945&r=mysqlcfg