|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73493 imap_fetchbody() [still] leaks memory
Submitted: 2016-11-11 04:55 UTC Modified: 2017-01-25 09:49 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: leeoniya at gmail dot com Assigned: mike (profile)
Status: Not a bug Package: IMAP related
PHP Version: 7.0Git-2016-11-11 (snap) OS: Win10 x64
Private report: No CVE-ID: None
 [2016-11-11 04:55 UTC] leeoniya at gmail dot com
It looks like this was an issue in the past that was resolved [1], but it looks like this is still a problem. If you run attached code on a mailbox of a few hundred messages, you can see the mem grow continuously. Using `imap_savebody()` also leaks.


Test script:
$imap = imap_open(IMAP_PATH, IMAP_USER, IMAP_PASS);
$uids = imap_sort($imap, SORTARRIVAL, 1, SE_UID | SE_NOPREFETCH);
$len = count($uids);

for ($i = 0; $i < $len; $i++)
  $raw = imap_fetchbody($imap, $uids[$i], "", FT_UID | FT_PEEK);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-23 20:43 UTC]
-Assigned To: +Assigned To: mike
 [2017-01-25 09:49 UTC]
-Status: Assigned +Status: Not a bug
 [2017-01-25 09:49 UTC]
These are no "leaks" per se. 

The c-client library performs a lot of caching, if you want to clean the caches, use imap_gc() <>.

See the diagrams at for a comparison of a session with and without calling imap_gc(IMAP_GC_TEXTS) every now and then.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 20:01:29 2024 UTC