Bug #60570 [Ver]: memory leak with create context

From: Date: Wed, 21 Dec 2011 15:07:41 +0000
Subject: Bug #60570 [Ver]: memory leak with create context
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166020@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60570&edit=1

 ID:                 60570
 Updated by:         cataphract@php.net
 Reported by:        roberto at spadim dot com dot br
 Summary:            memory leak with create context
 Status:             Verified
 Type:               Bug
 Package:            Streams related
 Operating System:   LINUX
 PHP Version:        5.3.8
 Block user comment: N
 Private report:     N

 New Comment:

The problem is simply that the context resource leaks everytime the http request fails. Seems to
have been introduce in r262454.


Previous Comments:
------------------------------------------------------------------------
[2011-12-21 15:03:29] roberto at spadim dot com dot br

maybe the array parameters isn´t being removed from memory? i tryed to change code 
inserting a comma after timeout parameter "'timeout'=>1," and it add more
memory 
leak per interaction more commas = more memory leak
 $context= stream_context_create(array('http'=>array('timeout'=>1,,,,,)));

------------------------------------------------------------------------
[2011-12-20 05:20:49] roberto at spadim dot com dot br

Description:
------------
hi, when i create a context inside a function i see a memory leak, but when i create it in the main
source code line, i don´t see it...
please check the script..

i think the problem is something that don´t leave memory get back when destroying context
variable

Test script:
---------------
memory leak:
<?php
function g(){
       
$context=stream_context_create(array('http'=>array('timeout'=>1)));
        $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
        unset($context);
        return($ret);
}
        $base=memory_get_usage();
        while(1){
                g();
                usleep(50000);
                echo    (memory_get_usage()-$base)."\n";
// memory get bigger and bigger here....
        }
?>

memory leak too:
<?php
        $base=memory_get_usage();
        while(1){
                $context=
stream_context_create(array('http'=>array('timeout'=>1)));
                $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
                usleep(50000);unset($ret,$context);
                echo    (memory_get_usage()-$base)."\n";
// memory get bigger and bigger...
        }
?>


nice:
<?php
        $base=memory_get_usage();
        $context=
stream_context_create(array('http'=>array('timeout'=>1)));
        while(1){
                $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
                usleep(50000);unset($ret);
                echo    (memory_get_usage()-$base)."\n";
// memory is nice here...
        }
?>



Expected result:
----------------
NICE:
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552


MEMORY LEAK:
Warning...
40120
Warning...
41344
Warning...
42568
Warning...
43792


Actual result:
--------------
well i think that others fields explain...

MEMORY LEAK:
Warning...
40120
Warning...
41344
Warning...



(+- 1224 per while interaction)

i don´t know how to solve this, unset don´t work, =null don´t work, and i don´t find a
function to destroy contexts...


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60570&edit=1


Thread (7 messages)

« previous php.bugs (#166020) next »