From:             myteamz at rogers dot com
Operating system: Windows XP SP2
PHP version:      5.2.3
PHP Bug Type:     Reproducible crash
Bug description:  memory allocation error using GD

Description:
------------
I am creating a script to produce a PNG image of a chart showing common
ancestors of several individuals, using the gd functionality supplied with
php.  After processing the input, including many calls to MySQL (version
5.0.2) all running on Apache 2.2 on Windows XP SP2, I am trying to allocate
the image resource.  This works for very small trees, but fails on all
calls with large trees.

The PHP error message is:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to
allocate 13770 bytes) in C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\GenChart\drawgraph.php on line 116

The offending code is:
$im = imagecreate ($xsize, $ysize);

Reproduce code:
---------------
Lots of memory allocation/freeing is occurring in the script prior to this
call.  I have included several debug lines prior to the offending call, as
below:

$memMax = ini_get("memory_limit");
$memUsed = memory_get_usage(true);
$xMax = round(30000000-intval($memUsed/$ysize),-3);
$xsize = min($xMax,max($xsize,4000));
dumpData("have used $memUsed of $memMax memory");
dumpData("trying to create image of size ($xsize,$ysize)");
$im = imagecreate ($xsize, $ysize);

The output, on crash, is

have used 6815744 of 32M memory
trying to create image of size (13770,990)

Expected result:
----------------
I have changed the script to produce standard HTML output for debugging
purposes, which allows me to get this info.  When running as intended, with
a small tree/image, the script should and does run successfully, creating
an image, and returning it as a .PNG image.  Running the same debug code
for a small image (with no crash), the output is:

have used 6553600 of 32M memory
trying to create image of size (4000,690)



Actual result:
--------------
When running in debug mode for a large tree/image, the debug output is:

have used 6815744 of 32M memory
trying to create image of size (13770,990)

When running as intended, the script fails and no image is returned to the
browser.

-- 
Edit bug report at http://bugs.php.net/?id=42356&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42356&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42356&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42356&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42356&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42356&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42356&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42356&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42356&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42356&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42356&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42356&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42356&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42356&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42356&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42356&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42356&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42356&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42356&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42356&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42356&r=mysqlcfg

Reply via email to