Ticket #2555 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

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

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

Change History

Changed 5 years ago by abajolet

Valgrind memcheck output

  Changed 5 years ago by assefa

  • owner changed from mapserverbugs to assefa
  • status changed from new to assigned
  • milestone set to 5.2 release

follow-up: ↓ 3   Changed 5 years ago by laurent

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   Changed 5 years ago by laurent

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

Changed 5 years ago by laurent

Changed 5 years ago by laurent

  Changed 5 years ago by assefa

Laurent,

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

  Changed 5 years ago by laurent

  • status changed from assigned to closed
  • resolution set to fixed

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.