Opened 16 years ago

Closed 16 years ago

#2525 closed defect (fixed)

gdImagePtr gdPImg memory leak in mapgd.c:msSaveImageBufferGD()

Reported by: richf Owned by: tamas
Priority: normal Milestone: 5.0.3 release
Component: MapServer C Library Version: 5.0
Severity: normal Keywords:
Cc: sdlime

Description

This was discovered while calling imageObj.getBytes() in java mapscript.

I will attach a patch that fixes the leak, courtesy of Tamas Szekeres.

This was discussed extensively in the mailing list thread:

leaking memory in java mapscript (was Re: thread safety) http://www.nabble.com/thread-safety-to15514019.html

But if you're trying to follow that there, you might want to skip ahead to at least the point at which I changed the subject line of the mailing list thread, after I realized that my problem was not a multithreading issue, but instead a memory leak. Skipping to here probably will suffice:

http://www.nabble.com/forum/ViewPost.jtp?post=15621043&framed=y

The leak was found on a hand compiled version of mapserver 5.0.0, with hand compiled versions of gd 2.0.35 and agg 2.5. Both on debian 3.1 (sarge) using gcc 3.3.5, swig 1.3.24, and Sun java 1.5.0_06:

MapServer version 5.0.0 OUTPUT=GIF OUTPUT=PNG OUTPUT=WBMP OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=THREADS INPUT=POSTGIS INPUT=SHAPEFILE

and on debian 4.0 (etch) using gcc 4.1.2, swig 1.3.29, and Sun java 1.5.0_14:

MapServer version 5.0.0 OUTPUT=GIF OUTPUT=PNG OUTPUT=WBMP OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=THREADS INPUT=JPEG INPUT=POSTGIS INPUT=SHAPEFILE

The leak was observed both via watching memory consumption of the java process in top, and using valgrind (3.2.0 on sarge, 3.2.1 on etch).

The leak was present using AGG (both with and without PALETTE_FORCE), but not present using GD. The leak was present regardless of whether the input was from PostGIS or from *.shp files.

I have so far just tested the fix on etch, but I have no reason to believe that the fix won't work on sarge as well.

I can attach a more complete .zip file containing all of my testcases showing how to observe the behavior both before and after the bugfix, if that is desired.

Attachments (2)

mapgd.c.diff (653 bytes ) - added by richf 16 years ago.
mapgd.c.diff
bug2525.zip (181.4 KB ) - added by richf 16 years ago.
This is not entirely a self contained testcase, but it might be a useful reference.

Download all attachments as: .zip

Change History (5)

by richf, 16 years ago

Attachment: mapgd.c.diff added

mapgd.c.diff

comment:1 by richf, 16 years ago

Cc: tamas added

comment:2 by tamas, 16 years ago

Cc: sdlime added; tamas removed
Milestone: 5.0.3 release
Owner: changed from sdlime to tamas

I take over this.

by richf, 16 years ago

Attachment: bug2525.zip added

This is not entirely a self contained testcase, but it might be a useful reference.

comment:3 by tamas, 16 years ago

Resolution: fixed
Status: newclosed

Applied the changes in trunk r7397 and branch-5-0 r7398

Note: See TracTickets for help on using tickets.