Permalink
Browse files

Fix memory leak when loading FORMATOPTIONS (#5149)

  • Loading branch information...
1 parent f404adf commit 4df5f9f11d87078cb853009a26a74a78615b41cc @tbonfort tbonfort committed Feb 24, 2016
Showing with 11 additions and 9 deletions.
  1. +11 −9 mapfile.c
View
@@ -5000,13 +5000,16 @@ static int loadOutputFormat(mapObj *map)
format->renderer = MS_RENDER_WITH_GD;
#endif
}
-
- format->numformatoptions = numformatoptions;
- if( numformatoptions > 0 ) {
- format->formatoptions = (char **)
- msSmallMalloc(sizeof(char *)*numformatoptions );
- memcpy( format->formatoptions, formatoptions,
- sizeof(char *)*numformatoptions );
+ while(numformatoptions--) {
+ char *key = strchr(formatoptions[numformatoptions],'=');
+ if(!key || !*(key+1)) {
+ msSetError(MS_MISCERR,"Failed to parse FORMATOPTION, expecting \"KEY=VALUE\" syntax.","loadOutputFormat()");
+ goto load_output_error;
+ }
+ *key = 0;
+ key++;
+ msSetOutputFormatOption(format,formatoptions[numformatoptions],key);
+ free(formatoptions[numformatoptions]);
}
format->inmapfile = MS_TRUE;
@@ -5047,8 +5050,7 @@ static int loadOutputFormat(mapObj *map)
if(getString(&value) == MS_FAILURE)
goto load_output_error;
if( numformatoptions < MAX_FORMATOPTIONS )
- formatoptions[numformatoptions++] = msStrdup(value);
- free(value);
+ formatoptions[numformatoptions++] = value;
value=NULL;
break;
case(IMAGEMODE):

0 comments on commit 4df5f9f

Please sign in to comment.