View Issue Details

IDProjectCategoryView StatusLast Update
0006861mantisbtotherpublic2006-04-20 06:30
Reportermlovell Assigned Toryandesign  
PrioritynormalSeveritymajorReproducibilityhave not tried
Status closedResolutionno change required 
PlatformAMD64OSRHELOS Version4
Product Version1.0.0 
Summary0006861: memory leak in core/file_api?
Description

After attaching three large files (~2.7MB) to an issue (each of which was below the file size limit), the httpd server started to emit the following error when trying to attaching a fourth file:


[client 10.1.24.24] PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 8753464 bytes) in /home/ma
ntis/core/file_api.php on line 598, referer: http://wally/mantis/view.php?id=43
The errors persisted until a restart of the Apache server. I also increased PHP's memory limit from 32MB to 64MB.

This is the first time I have seen the above error. Is file_api.php not releasing memory used in the MySQL update queries? The typical size for an httpd process appears to be about 28MB (with 10MB shared). We are running Apache/2.0.52 (Red Hat) with PHP 4.3.9.

I'll start reading through the code in the area of the error message, but thought it would be worthwhile to file this issue.

TagsNo tags attached.

Activities

mlovell

mlovell

2006-03-16 17:27

reporter   ~0012357

Thinking through this scenario further, I think the issue was entirely the size of the last file we were attempting to attach. Although the file was below the caps set for uploads/updates by PHP and MySQL, it was still a 5MB file. If the entire file contents must be read into PHP in order to form the SQL query, the resulting process would indeed be over the 32MB limit set by /etc/php.ini.

Thus, the error was most likely not due to some cumulative effect of the large uploads. Instead, the overall PHP memory limit should have been increased when I increased the upload limit.

If you concur, this issue can probably be deleted.

ryandesign

ryandesign

2006-03-16 20:24

reporter   ~0012358

Yes, unfortunately file_api.php seems to keep the entire contents of the file in memory, in an encoded state, twice: in $c_content and in $query. The encoded state is produced (for MySQL users) by running the file's content through mysql_real_escape_string(). I tested with a 1.5MB Photoshop file and the encoded version was 16% larger. So PHP will need memory equal to about 2.32 times the size of the file, in addition to the several megs PHP requires for any script.