|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74387 php-cgi process leaks memory after killing script due to max_execution_time
Submitted: 2017-04-06 17:10 UTC Modified: 2017-04-10 23:01 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: nocheck-php at bsrealm dot net Assigned: danack (profile)
Status: Assigned Package: imagick (PECL)
PHP Version: PHP 7.0.15-0ubuntu0.16.04.4 OS: Ubuntu 16.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-04-06 17:10 UTC] nocheck-php at bsrealm dot net
Setup is Lighttpd with php configured as fcgi module.

Repeated execution of provided script will lead to some serious memory leaks (200-500 MB per process). Image should be huge enough. I used this one:

Test script:
    header("Content-Type: text/plain");
    ini_set('max_execution_time', 10);
    $st_tm = time();
    $diff = 0;
    while (1){
        $image = new \Imagick(realpath('./IMG_2466.JPG'));
        $image->thumbnailImage(64, 48, true, false);
        $image = null;
        if ((time() - $st_tm) > $diff) {
            $diff = (time() - $st_tm);
            echo "Waiting to Die " . date('h:i:s') . "\n";

Expected result:
All memory should be freed after script is killed.

Actual result:
Memory is not freed.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-06 17:14 UTC] nocheck-php at bsrealm dot net
-PHP Version: 7.0.17 +PHP Version: PHP 7.0.15-0ubuntu0.16.04.4
 [2017-04-06 17:14 UTC] nocheck-php at bsrealm dot net
Fixed version.
 [2017-04-06 17:24 UTC] nish dot aravamudan at canonical dot com
Note that in (original report), we also tested 7.0.17 and found the issue to still be present there.
 [2017-04-10 11:51 UTC]
-Package: CGI/CLI related +Package: imagick -Assigned To: +Assigned To: danack
 [2017-04-10 11:51 UTC]
@danack: Assuming this is related to imagick...
 [2017-04-10 23:01 UTC]
This appears to be reproducible from CLI also, or at least valgrind reports there are large allocations that haven't been freed before the program exits.

Just to note though - having any web server that faces the public internet use Imagick to process images directly is probably a bad idea:
 [2017-04-13 16:36 UTC] nocheck-php at bsrealm dot net
This is a problem inside of Imagick, but this doesn't mean php should assume there are no bugs in plugins, right? Can it be fixed or worked around on php level?
 [2017-04-26 10:38 UTC]
"Can it be fixed or worked around on php level?"

Almost certainly not.

The memory is being allocated by ImageMagick, which PHP doesn't hook into. The problem appears to be related to the request shutdown function not being called, which means that ImageMagick isn't aware that it needs to release the memory it has allocated.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC