From:             jake dot levitt at mailtrust dot com
Operating system: Ubuntu 8.04 (linux:2.6.24-21)
PHP version:      5.2.9
PHP Bug Type:     Reproducible crash
Bug description:  imap_body causes memory leak

Description:
------------
I am creating a script that migrates e-mail from one server to another. 
On really large mailboxes, my script dies with "PHP Fatal error:  Out of
memory (allocated 13631488) (tried to allocate 3381512 bytes)" even though
memory_get_usage() function was reporting that the script was only using
around 10 MBs.  My memory_limit is set to 1GB (but this isn't coming into
play). When I examined the memory usage of the script using ps, I noticed
that it would gradually increase until it reached ~92% of system memory (I
have 2GB).  I eventually found that when I commented out imap_body, the
memory usage would stay flat.  I wrote a script that can reproduce this
bug.  I run the script in the background and then watch its memory using:
ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid | grep
"\(memory-usage\)\|\(PID\)" | grep -v grep.  Please let me know if you need
additional information.  This script is intended to be run on the cli.

Reproduce code:
---------------
<?php
$flags = '/novalidate-cert';
$host = 'mail.server.com:143';
$username = 'user';
$password = 'pass';
$folder = 'INBOX';

$base_imap_string = '{' . $host . $flags . '}';
$connect_string = $base_imap_string . $folder;

$mailbox = @imap_open($connect_string, $username, $password, 0, 3);
$reopen_success = imap_reopen($mailbox, $connect_string, 0, 3);

$message_ids = imap_search($mailbox, "ALL", SE_UID);
for ($i = 0; $i < 10000000; $i++) {
    imap_body($mailbox, $message_ids[0], FT_UID | FT_PEEK);
}

Expected result:
----------------
I would expect that memory usage as viewed by the ps command stays
relatively flat.

Actual result:
--------------
Memory usage as viewed by the ps command increases over time until the
script eventually dies with an "out of memory" error given.

-- 
Edit bug report at http://bugs.php.net/?id=47940&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47940&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47940&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47940&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47940&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47940&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47940&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47940&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47940&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47940&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47940&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47940&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47940&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47940&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47940&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47940&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47940&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47940&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47940&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47940&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47940&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47940&r=mysqlcfg

Reply via email to