php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20470 With builtin GD, memory leak and segfault
Submitted: 2002-11-17 20:20 UTC Modified: 2002-11-19 13:57 UTC
From: oldwolf at xtra dot co dot nz Assigned: derick (profile)
Status: Closed Package: GD related
PHP Version: 4.3.0-dev/4.4.0-dev OS: Linux 2.2.19
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: oldwolf at xtra dot co dot nz
New email:
PHP Version: OS:

 

 [2002-11-17 20:20 UTC] oldwolf at xtra dot co dot nz
I have a PHP script for outputting a PNG image. It uses the following functions:
  ImageCreateFromPNG
  ImageColorClosest
  ImageTTFText
  ImageTTFBBox
  ImageLine
  ImagePNG
  ImageDestroy

This worked correctly with PHP 4.0.6 , GD 1.8.4, FreeType 1.3.1. (At the time I first installed PHP4, these were the latest versions of GD and FreeType that behaved properly). 

When I upgraded to PHP 4.3.0RC1, with builtin GD, executing the same script produced memory leak errors in the Apache log:

/usr/local/src/php-4.3.0RC1/ext/gd/libgd/gdhelpers.c(89) :  Freeing 0x082B9CE4 (8 bytes), script=/u/www/paygate/cheque-image.php
Last leak repeated 270 times
/usr/local/src/php-4.3.0RC1/ext/gd/libgd/gdhelpers.c(89) :  Freeing 0x082BDDA4 (8 bytes), script=/u/www/paygate/cheque-image.php
[Mon Nov 18 12:48:04 2002] [notice] child pid 10950 exit signal Segmentation fault (11)
/usr/local/src/php-4.3.0RC1/ext/gd/libgd/gdhelpers.c(89) :  Freeing 0x082B8B84 (8 bytes), script=/u/www/paygate/cheque-image.php
Last leak repeated 264 times

Sometimes the image would still display correctly anyway, and sometimes there would be no output (presumably corresponding to those times that Apache segfaulted, although I did not check this explicitly).

I found that I could correct the problem by not using the builtin GD. This required two steps:
  -- modify my ./configure command to use --with-gd=/path/to/gd instead of --with-gd
  -- modify php_config.h to say HAVE_GD_GD2 0  (in 2 places), ./configure did not pick up automatically that my installed GD was 1.x 

After rebuilding with these GD settings the image was generated correctly with no memory leaks and no segfaults.

I guess therefore that there is something wrong with the builtin GD code.

Here is my ./configure line (that generates the buggy version):

./configure --with-mcrypt --with-mhash --with-mysql=../../mysql --with-gd --enable-versioning --with-ttf --enable-shared --enable-freetype-4bit-antialias-hack --with-informix --with-bz2 --with-gmp --with-zlib --enable-sockets --with-config-dir=/usr/local/etc --enable-debug --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --without-pear --with-apxs

When using "--with-gd", phpinfo() displays "GD Version" as "bundled (2.0 compatible)" and "GIF Support" as "enabled". When using "--with-gd=/path/to/gd", phpinfo() displays "GD Version" as "1.6.2 or higher" and does not display the "GIF Support" line. All other GD fields stay the same (ie. "enabled", except for "FreeType Linkage" which is "with TTF library").

Thanks,
Matt.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-17 20:44 UTC] nicos@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.
 [2002-11-17 20:56 UTC] nicos@php.net
Even with Derick's patch we still have some memory lacks so we open it back.
 [2002-11-17 20:56 UTC] iliaa@php.net
This bug is actually valid.
 [2002-11-19 13:57 UTC] iliaa@php.net
4.3.0 tree has been reverted to old memory allocation scheme.
In 4.4.0 the persistent allocation problem has been resolved.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 08:05:45 2022 UTC