[Mapserver-dev] [PATCH] mapswf and mappdf memory leaks

Daniel Morissette dmorissette at dmsolutions.ca
Fri May 28 14:41:44 EDT 2004


Mladen Turk wrote:
> Hi all,
> 
> The patch resolves memory leaks in mapswf and mappdf caused by multiple
> strdup's on a single variable (driver).
> 
> Interesting that the code (using const char *, instead strdup) already
> exists in a part of mapswf.
> 
> 
> MT.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: mapswf.c
> ===================================================================
> RCS file: /data2/cvsroot/mapserver/mapswf.c,v
> retrieving revision 1.36
> diff -u -r1.36 mapswf.c
> --- mapswf.c	11 May 2004 13:54:29 -0000	1.36
> +++ mapswf.c	28 May 2004 06:25:41 -0000
> @@ -17,6 +17,8 @@
>  #include <assert.h>
>  #if !defined(_WIN32)
>  #include <zlib.h>
> +#else
> +#include "zlib.h"
>  #endif
>  #include "map.h"
>  
> @@ -824,7 +826,7 @@
>  {
>  
>      imageObj    *image = NULL;
> -    char        *driver = strdup("GD/GIF");
> +    const char  *driver = "GD/GIF";
>  
>      assert( strcasecmp(format->driver,"SWF") == 0 );
>      image = (imageObj *)calloc(1,sizeof(imageObj));
> @@ -875,19 +877,19 @@
>      else
>      {
>  #ifdef USE_GD_GIF
> -        driver = strdup("GD/GIF");
> +        driver = "GD/GIF";
>  #else  
>  
>  #ifdef USE_GD_PNG
> -        driver = strdup("GD/PNG");
> +        driver = "GD/PNG";
>  #else
>  
>  #ifdef USE_GD_JPEG
> -        driver = strdup("GD/JPEG");
> +        driver = "GD/JPEG";
>  #else
>  
>  #ifdef USE_GD_WBMP
> -        driver = strdup("GD/WBMP");
> +        driver = "GD/WBMP";
>  #endif 
>  
>  #endif
> @@ -2858,23 +2860,23 @@
>      imageObj    *imagetmp;
>      //int         nTmp = -1;
>      SWFShape    oShape;
> -    char        *driver = strdup("GD/GIF");
> +    const char  *driver = "GD/GIF";
>      int         bFreeImage = 0;
>  
>  #ifdef USE_GD_GIF
> -    driver = strdup("GD/GIF");
> +    driver = "GD/GIF";
>  #else  
>  
>  #ifdef USE_GD_PNG
> -     driver = strdup("GD/PNG");
> +     driver = "GD/PNG";
>  #else
>  
>  #ifdef USE_GD_JPEG
> -     driver = strdup("GD/JPEG");
> +     driver = "GD/JPEG";
>  #else
>  
>  #ifdef USE_GD_WBMP
> -     driver = strdup("GD/WBMP");
> +     driver = "GD/WBMP";
>  #endif 
>  
>  #endif
> Index: mappdf.c
> ===================================================================
> RCS file: /data2/cvsroot/mapserver/mappdf.c,v
> retrieving revision 1.22
> diff -u -r1.22 mappdf.c
> --- mappdf.c	8 May 2003 04:54:02 -0000	1.22
> +++ mappdf.c	28 May 2004 06:26:41 -0000
> @@ -128,7 +128,7 @@
>      imageObj    *oImage = NULL;
>      PDF *pdf = NULL;
>  
> -    char        *driver = strdup("GD/GIF");
> +    const char  *driver = "GD/GIF";
>  
>      assert( strcasecmp(format->driver,"PDF") == 0 );
>  
> @@ -186,19 +186,19 @@
>      else
>      {
>  #ifdef USE_GD_GIF
> -        driver = strdup("GD/GIF");
> +        driver = "GD/GIF";
>  #else  
>  
>  #ifdef USE_GD_PNG
> -        driver = strdup("GD/PNG");
> +        driver = "GD/PNG";
>  #else
>  
>  #ifdef USE_GD_JPEG
> -        driver = strdup("GD/JPEG");
> +        driver = "GD/JPEG";
>  #else
>  
>  #ifdef USE_GD_WBMP
> -        driver = strdup("GD/WBMP");
> +        driver = "GD/WBMP";
>  #endif 
>  
>  #endif
> @@ -1452,7 +1452,7 @@
>      PDF                 *pdf = NULL;
>      imageObj            *image_tmp = NULL;
>      int                 iReq = -1;
> -    char                *driver = strdup("GD/GIF");
> +    const char          *driver = "GD/GIF";
>      char                *jpeg = NULL;
>      int                 nLength = 0, nResult = 0;
>      //char                ttt[200];
> @@ -1460,19 +1460,19 @@
>      int                 bRasterOutput = 0;
>  
>  #ifdef USE_GD_GIF
> -    driver = strdup("GD/GIF");
> +    driver = "GD/GIF";
>  #else  
>  
>  #ifdef USE_GD_PNG
> -     driver = strdup("GD/PNG");
> +     driver = "GD/PNG";
>  #else
>  
>  #ifdef USE_GD_JPEG
> -     driver = strdup("GD/JPEG");
> +     driver = "GD/JPEG";
>  #else
>  
>  #ifdef USE_GD_WBMP
> -     driver = strdup("GD/WBMP");
> +     driver = "GD/WBMP";
>  #endif 
>  
>  #endif


-- 
------------------------------------------------------------
  Daniel Morissette               dmorissette at dmsolutions.ca
  DM Solutions Group              http://www.dmsolutions.ca/
------------------------------------------------------------




More information about the mapserver-dev mailing list