php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nocheck-php at bsrealm dot net
New email:
PHP Version: OS:

 

 [2017-04-06 17:10 UTC] nocheck-php at bsrealm dot net
Description:
------------
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: http://home.bsrealm.net/IMG_2466.JPG

Test script:
---------------
<?php
    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->clear;
        $image = null;
        if ((time() - $st_tm) > $diff) {
            $diff = (time() - $st_tm);
            echo "Waiting to Die " . date('h:i:s') . "\n";
            flush();
        }
    }
?>

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

Actual result:
--------------
Memory is not freed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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 https://bugs.launchpad.net/bugs/1677578 (original report), we also tested 7.0.17 and found the issue to still be present there.
 [2017-04-10 11:51 UTC] nikic@php.net
-Package: CGI/CLI related +Package: imagick -Assigned To: +Assigned To: danack
 [2017-04-10 11:51 UTC] nikic@php.net
@danack: Assuming this is related to imagick...
 [2017-04-10 23:01 UTC] danack@php.net
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: https://github.com/mkoppanen/imagick#security
 [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] danack@php.net
"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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC