php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16149 Memory leak with refcount limit.
Submitted: 2002-03-18 13:13 UTC Modified: 2002-06-18 04:58 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: vincent at ecbar dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.2.1-dev OS: ANY
Private report: No CVE-ID: None
 [2002-03-18 13:13 UTC] vincent at ecbar dot com
try the follow code, it works on 4.0.6 but "Segmentation fault (core dumped)" on CGI version and give no error message (and appear to keep executing the code few more times on other httpd child process too) on dynamic apache module version.

i've memory limited to 8M, and it's fine when for lopp as "$i<8000".

<?php
$file = "-----";
for ($i = 0; $i<9000 ; $i++) {
     $result_array["one"][$i] = $file;
     $result_array["two"][$i] = $file;
     $result_array["three"][$i] = $file;
     $result_array["four"][$i] = $file;
     $result_array["five"][$i] = $file;
     $result_array["six"][$i] = $file;
     $result_array["seven"][$i] = $file;
     $result_array["eight"][$i] = $file;

}
echo "done<BR>";
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-19 04:22 UTC] sander@php.net
To properly diagnose this bug, we need a backtrace to see what is
happening behind the scenes. To find out how to generate a backtrace,
please read http://bugs.php.net/bugs-generating-backtrace.php

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open".


 [2002-03-19 04:36 UTC] yohgaki@php.net
This must be refcount limitation.
I see memory leak with 4.2.1-dev and 4.2.0-dev.

Scripting engine problem.
This problem may be suspended. It's not simple to fix.

May be we should let PHP die if refcount reached it's limit.


[yohgaki@dev HEAD]$ ./sapi/cli/php 
<?php
$file = "-----";
for ($i = 0; $i<9000 ; $i++) {
     $result_array["one"][$i] = $file;
     $result_array["two"][$i] = $file;
     $result_array["three"][$i] = $file;
     $result_array["four"][$i] = $file;
     $result_array["five"][$i] = $file;
     $result_array["six"][$i] = $file;
     $result_array["seven"][$i] = $file;
     $result_array["eight"][$i] = $file;

}
echo "done<BR>";
?>

done<BR>
[Tue Mar 19 18:41:50 2002]  Script:  '-'
---------------------------------------
/home/yohgaki/cvs/php/HEAD/Zend/zend_execute.h(62) : Block 0x082AC068 status:
Beginning:      Cached (allocated on /home/yohgaki/cvs/php/HEAD/Zend/zend_execute.c:467, 12 bytes)
      End:      OK
---------------------------------------
[yohgaki@dev HEAD]$  ./sapi/cli/php -v 
4.2.1-dev
[yohgaki@dev HEAD]$ 




 [2002-03-19 11:07 UTC] vincent at ecbar dot com
we are using lots of arrays in php and have to roll back to 4.0.6 as some of our script won't work on 4.1.2. 

i am not a php core developer, can you provide us further information regarding the refcount problem?
 [2002-03-19 12:47 UTC] zeev@php.net
Yasuo - what you're seeing is not a leak, but a crash report (it tried to free a block which was already freed).  Lots of these double frees are caught by the cache and in debug mode, they are displayed.

Vincent - there's no immediate solution to the problem, other than avoiding the use of the same value more than 64K times.  Do you really have to assign $file to that many places?

If you really do, you can edit Zend/zend.h, look for the line:
 zend_ushort refcount;

change it to:
 uint refcount;

And recompile (make clean; make)



 [2002-03-19 14:34 UTC] vincent at ecbar dot com
thanks a lot, i think we get into this refcount problem by mistake. infact, we don't need to assign a single variable more than 64k times. we were trying to reproduce a memory leak bug in apache module which only occur when we upgraded to 4.1.2.

we are getting core dump or memory leak problem(httpd process won't release the memory until it die) we are not yet able to reproduce it.

for eg, one of the interesting case is, everything works fine except when your change a file to not writable and have the following code

... some arrays which use up to 3M ..

if ( $fd = fopen($indexfile, "w")) {
...
}

apache process will not release the used memory anymore.

if we change to

if ( $fd = @fopen($indexfile, "w")) 

it works, if the file doesn't exist and the directory isn't writable it will works too

anyway, thx for the info. we'll try to reproduce our problem when we have the time.
 [2002-03-20 18:40 UTC] yohgaki@php.net
Thanks Zeev.
I didn't try to understand the error.

I thought we are going to allocate new zval. 
 [2002-06-18 04:58 UTC] derick@php.net
Vincent, if there are furhter comments on this, feel free to reopen this report and add your comments.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 12 09:01:27 2024 UTC