Skip to content

Commit 4df5f9f

Browse files
committed
Fix memory leak when loading FORMATOPTIONS (#5149)
1 parent f404adf commit 4df5f9f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

mapfile.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,13 +5000,16 @@ static int loadOutputFormat(mapObj *map)
50005000
format->renderer = MS_RENDER_WITH_GD;
50015001
#endif
50025002
}
5003-
5004-
format->numformatoptions = numformatoptions;
5005-
if( numformatoptions > 0 ) {
5006-
format->formatoptions = (char **)
5007-
msSmallMalloc(sizeof(char *)*numformatoptions );
5008-
memcpy( format->formatoptions, formatoptions,
5009-
sizeof(char *)*numformatoptions );
5003+
while(numformatoptions--) {
5004+
char *key = strchr(formatoptions[numformatoptions],'=');
5005+
if(!key || !*(key+1)) {
5006+
msSetError(MS_MISCERR,"Failed to parse FORMATOPTION, expecting \"KEY=VALUE\" syntax.","loadOutputFormat()");
5007+
goto load_output_error;
5008+
}
5009+
*key = 0;
5010+
key++;
5011+
msSetOutputFormatOption(format,formatoptions[numformatoptions],key);
5012+
free(formatoptions[numformatoptions]);
50105013
}
50115014

50125015
format->inmapfile = MS_TRUE;
@@ -5047,8 +5050,7 @@ static int loadOutputFormat(mapObj *map)
50475050
if(getString(&value) == MS_FAILURE)
50485051
goto load_output_error;
50495052
if( numformatoptions < MAX_FORMATOPTIONS )
5050-
formatoptions[numformatoptions++] = msStrdup(value);
5051-
free(value);
5053+
formatoptions[numformatoptions++] = value;
50525054
value=NULL;
50535055
break;
50545056
case(IMAGEMODE):

0 commit comments

Comments
 (0)