#47940 [Opn->Asn]: imap_body() leaks memory
| From: | pajoye@php.net | Date: | Fri, 24 Apr 2009 17:51:27 +0000 |
| Subject: | #47940 [Opn->Asn]: imap_body() leaks memory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-136218@lists.php.net to get a copy of this message | ||
ID: 47940
Updated by: pajoye@php.net
Reported By: jake dot levitt at mailtrust dot com
-Status: Open
+Status: Assigned
Bug Type: IMAP related
Operating System: Ubuntu 8.04 (linux:2.6.24-21)
PHP Version: 5.2.9
-Assigned To:
+Assigned To: pajoye
New Comment:
Will test it using my test imap server. The last fix is correct but
there is certainly other sources of leaks.
Previous Comments:
------------------------------------------------------------------------
[2009-04-24 17:47:45] jake dot levitt at mailtrust dot com
Hey guys it looks like we were a little hasty in submitting this patch.
It now seems that our patch does lessen the memory leak, but does not
eradicate it. We ran our test script using the patch and it seemed to
work, but running the actual migration program shows that there is still
a leak. Before our program would migrate ~1.5gb of mail now it migrates
~2.4gb before running out of memory. We have updated our test script to
better expose the memory leak:
/**
* To watch memory usage use:
* ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid | grep
"\(memory-usage-test\)\|\(PID\)" | grep -v grep
*/
$flags = '/novalidate-cert';
$host = 'a.host.com:143';
$username = 'a.user@a.host.com';
$password = 'password';
$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);
$num_msgs = count($message_ids);
for ($i = 0; $i < 1000000; $i++) {
$msg_num = $i % $num_msgs;
imap_body($mailbox, $message_ids[$msg_num], FT_UID);
}
------------------------------------------------------------------------
[2009-04-23 22:35:57] pajoye@php.net
Slightly modified version committed in all branches. Thanks for your
work!
------------------------------------------------------------------------
[2009-04-23 21:37:27] jake dot levitt at mailtrust dot com
Here's a unified diff:
diff -u php-5.2.9/ext/imap/php_imap.c
php-5.2.9-fixed/ext/imap/php_imap.c
--- php-5.2.9/ext/imap/php_imap.c 2008-12-31 06:17:38.000000000
-0500
+++ php-5.2.9-fixed/ext/imap/php_imap.c 2009-04-23
13:56:26.000000000 -0400
@@ -1250,7 +1250,10 @@
RETURN_FALSE;
}
- RETVAL_STRING(mail_fetchtext_full
(imap_le_struct->imap_stream, Z_LVAL_PP(msgno), NIL, myargc==3 ?
Z_LVAL_PP(pflags) : NIL), 1);
+ char *body = mail_fetchtext_full (imap_le_struct->imap_stream,
Z_LVAL_PP(msgno), NIL, myargc==3 ? Z_LVAL_PP(pflags) : NIL);
+
+ RETVAL_STRING(body, 1);
+ free(body);
}
/* }}} */
------------------------------------------------------------------------
[2009-04-23 21:03:39] scottmac@php.net
Can you provide the patch as a unified diff, just use the -u flag to
cvs diff.
------------------------------------------------------------------------
[2009-04-23 19:05:24] jake dot levitt at mailtrust dot com
A co-worker and I have created a diff that seems to fix this issue.
Would someone else mind checking it out and seeing if there are any
problems with it?
diff php_imap.c php_imap_fixed.c
1251a1252
> char *body = mail_fetchtext_full (imap_le_struct->imap_stream,
Z_LVAL_PP(msgno), NIL, myargc==3 ? Z_LVAL_PP(pflags) : NIL);
1253c1254,1255
< RETVAL_STRING(mail_fetchtext_full (imap_le_struct->imap_stream,
Z_LVAL_PP(msgno), NIL, myargc==3 ? Z_LVAL_PP(pflags) : NIL), 1);
---
> RETVAL_STRING(body, 1);
> free(body);
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/47940
--
Edit this bug report at http://bugs.php.net/?id=47940&edit=1