php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63207 Passed in string type of ImagickPixel parameter cause a memory leak
Submitted: 2012-10-03 11:43 UTC Modified: 2013-12-03 13:02 UTC
From: hightman at twomice dot net Assigned: mkoppanen (profile)
Status: Closed Package: imagick (PECL)
PHP Version: 5.3.17 OS: MacOS
Private report: No CVE-ID: None
 [2012-10-03 11:43 UTC] hightman at twomice dot net
Description:
------------
In Imagick object, there are many method functions contain parameters of type ImagickPixel.

For convenience, these parameters allow using a string that represents a color, such as  '#000000'.

After the end of the function call, the ImagickPixel object generated by these parameters will not be destroyed timely. These resources are only released after the end of the whole request.

Test script:
---------------
<?php
$im = new Imagick();
$im->newImage(100, 100, 'none');

for ($i = 0; $i < 1000; $i++)
{
    $color = sprintf('#%06X', mt_rand(0, 0xffffff));
    // NOTICE: If you remove the comment of below line, will not cause a memory leak
    //$color = new ImagickPixel($color);
    $im->borderImage($color, 2, 2); 
    if ($i > 0 && ($i % 100) == 0)
    {   
        echo "[$i] memory: " . number_format(memory_get_usage()) . "\n";
    }   
}

Expected result:
----------------
[100] memory: 633,648
[200] memory: 633,648
[300] memory: 633,648
[400] memory: 633,648
[500] memory: 633,648

Actual result:
--------------
[100] memory: 677,712
[200] memory: 722,512
[300] memory: 767,312
[400] memory: 812,112
[500] memory: 856,912
[600] memory: 967,248

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-03 11:29 UTC] mike@php.net
-Assigned To: +Assigned To: mkoppanen
 [2013-12-03 13:01 UTC] mkoppanen@php.net
I think this has been fixed in later versions:

$ php -n -d extension_dir=modules/ -d extension=imagick.so t.php
[100] memory: 227,128
[200] memory: 227,160
[300] memory: 227,160
[400] memory: 227,160
^C
 [2013-12-03 13:02 UTC] mkoppanen@php.net
-Status: Assigned +Status: Closed
 [2013-12-03 13:02 UTC] mkoppanen@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 11:01:34 2024 UTC