Opened 16 years ago

Closed 16 years ago

#2555 closed defect (fixed)

memory leaks in mapswf.c

Reported by: abajolet Owned by: assefa
Priority: normal Milestone: 5.2 release
Component: Output-SWF Version: svn-trunk (development)
Severity: normal Keywords:
Cc:

Description

Hello,

It seems that SWF (Flash) output leaks memory from various portions of code. From mapswf.c

  • In function SWFShape gdImage2Shape(gdImagePtr img), adding
free(data);

before returning oShape corrects a serious leak. "data" is malloc() in gd2bitmap but not free() anywhere.

Tested with valgrind :

Before :

==2001== 307,593 bytes in 1 blocks are possibly lost in loss record 29 of 30
==2001==    at 0x40218B8: malloc (vg_replace_malloc.c:207)
==2001==    by 0x80873FB: gd2bitmap (mapswf.c:385)
==2001==    by 0x808776B: gdImage2Shape (mapswf.c:445)
...
==2001==      possibly lost: 307,593 bytes in 1 blocks

After :

==13249== possibly lost: 0 bytes in 0 blocks

  • When using true type labels, it seems the SWFFont ressources are not destroyed by msFreeImageSWF

See the attached valgrind output file.

==13149== 60,733 (360 direct, 60,373 indirect) bytes in 5 blocks are definitely lost in loss record 42 of 56
==13149==    at 0x40218B8: malloc (vg_replace_malloc.c:207)
==13149==    by 0x48F2F3E: newSWFFont (font.c:301)
==13149==    by 0x48F2FE8: loadSWFFontFromFile (font.c:969)
==13149==    by 0x80859D5: DrawText (mapswf.c:1633)
...
==13149==    indirectly lost: 66,229 bytes in 77 blocks

The leak is very important, and in an Apache/PHP/php_mapscript context, the memory usage grows very quickly when the layers with labels are rendered.

  • Environnement :

Leaks tested with shp2img - Mapserver 5.0 SVN - Ming 0.3.0 Growing memory usage with Apache 2.2.x, PHP 5.2.5, php_mapscript

Regards, Antoine Bajolet

Attachments (3)

valgrind-swf-font.log (6.2 KB ) - added by abajolet 16 years ago.
Valgrind memcheck output
mapswf.c (128.6 KB ) - added by laurent 16 years ago.
mapswf.h (1.5 KB ) - added by laurent 16 years ago.

Download all attachments as: .zip

Change History (8)

by abajolet, 16 years ago

Attachment: valgrind-swf-font.log added

Valgrind memcheck output

comment:1 by assefa, 16 years ago

Milestone: 5.2 release
Owner: changed from mapserverbugs to assefa
Status: newassigned

comment:2 by laurent, 16 years ago

Here's a version of mapswf.c and mapswf.h I've adjusted to correct those memory leaks. It seems to work quite well on the system I use.

in reply to:  2 comment:3 by laurent, 16 years ago

Assefa, some things on the buttons need to be tested as I don't have the correct mapfile to do so, I've flagged it with a TODO. Nevertheless, I think every buttons should be listed by StoreButton() to be properly destroyed in the end by msFreeImageSWF() Regards, Laurent Baey

by laurent, 16 years ago

Attachment: mapswf.c added

by laurent, 16 years ago

Attachment: mapswf.h added

comment:4 by assefa, 16 years ago

Laurent,

committed in r7488. If there are no more additions to this, please mark the bug as fixed and close. Thanks for this work.

comment:5 by laurent, 16 years ago

Resolution: fixed
Status: assignedclosed

No more addition, for now : there might be other memory leaks on the same scheme in SWF features I don't use. Thanks Assefa.

Note: See TracTickets for help on using tickets.