php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35893 imap_fetch_overview() leaks
Submitted: 2006-01-04 14:30 UTC Modified: 2006-01-10 16:46 UTC
From: erik at phpcastle dot com Assigned: iliaa (profile)
Status: Not a bug Package: IMAP related
PHP Version: 5.1.1 OS: Debian
Private report: No CVE-ID: None
 [2006-01-04 14:30 UTC] erik at phpcastle dot com
Description:
------------
Fist of all I use version 5.0.4-1

When opening an imap connection and then performing an imap_fetch_overview the memory usage is increasing every time I call imap_fetch_overview.

Reproduce code:
---------------
http://phpcastle.com/memusage_test.phps

Actual result:
--------------
-------Start-------
Memory usage: 62488	- Next: Open connection
Memory usage: 62544	- Next: Imap check
Memory usage: 62968	- Next: Clear $mailboxinfo
Memory usage: 62968	- Next: Fetch Overview
----------Num msg: 10-----
Memory usage: 74448	- Next: Clear Overview
Memory usage: 74448	- Next: Close connection
Memory usage: 74448	- Next: Clear imap stream
Memory usage: 74448	- Next: Open connection
Memory usage: 74448	- Next: Imap check
Memory usage: 74448	- Next: Clear $mailboxinfo
Memory usage: 74448	- Next: Fetch Overview
----------Num msg: 10-----
Memory usage: 75152	- Next: Clear Overview
Memory usage: 75152	- Next: Close connection
Memory usage: 75152	- Next: Clear imap stream
Memory usage: 75152	- Next: Open connection
Memory usage: 75152	- Next: Imap check
Memory usage: 75152	- Next: Clear $mailboxinfo
Memory usage: 75152	- Next: Fetch Overview
----------Num msg: 10-----
Memory usage: 75872	- Next: Clear Overview
Memory usage: 75872	- Next: Close connection
Memory usage: 75872	- Next: Clear imap stream
Memory usage: 75872	- Next: Open connection
Memory usage: 75872	- Next: Imap check
Memory usage: 75872	- Next: Clear $mailboxinfo
Memory usage: 75872	- Next: Fetch Overview
----------Num msg: 10-----
Memory usage: 76576	- Next: Clear Overview
Memory usage: 76576	- Next: Close connection
Memory usage: 76576	- Next: Clear imap stream
Memory usage: 76576	-------End------- 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-05 01:39 UTC] erik at phpcastle dot com
I've tried also with php 5.1.1 for debian and didn't help either :)
 [2006-01-05 21:31 UTC] tony2001@php.net
Assigned to the maintainer.
 [2006-01-08 19:45 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

There is no bug here, the return value of imap_fetch_overview() is a complex array that contains objects within it. If you trully want to "free" it you need to itterate through the array freeing each element individually.
 [2006-01-10 14:36 UTC] erik at phpcastle dot com
Well.... I've tested in another way by putting imap_fetch_overview in a function. When the function ends the memory should be free right?

Not in this case.

<?php
	echo "Memory usage: " . memory_get_usage() . "\t- Before fetch_overview function\n";			
	testclear ($stream);
	echo "Memory usage: " . memory_get_usage() . "\t- After fetch_overview function\n\n";			

function testclear($stream) {
	$imapOverview = imap_fetch_overview($stream, "1:*");
}
?>

My result is still the same:
Memory usage: 50264	- Before fetch_overview function
Memory usage: 89936	- After fetch_overview function

Memory usage: 89800	- Before fetch_overview function
Memory usage: 94608	- After fetch_overview function

Memory usage: 94472	- Before fetch_overview function
Memory usage: 97232	- After fetch_overview function

Memory usage: 97096	- Before fetch_overview function
Memory usage: 97232	- After fetch_overview function

I had also unset each object from the result array and it did not help anything
 [2006-01-10 16:46 UTC] iliaa@php.net
Putting the code into the function would not force the freeing of memory in this case. Unless you explicitly free it yourself you'll need to wait till the script termination time.
By defention a leak in PHP would be a situation where at the end of the script's execution memory allocated for the purpose of running the script was not freed.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 05:05:53 2022 UTC