Before setting any formatoption from mapfile, make sure to free previous formatoptions as allocated by the default formats.
This slightly modifies the behaviour. Previously it would always overwrite the numformatoptions and thus preventing any use of the default format options. Now it preserves the default format options if none are specified. I'm not sure what behaviour is required. It should be easy to change though if needed.
Fix memory leak when setting format options from mapfile
I think this patch needs to be reworked to use msSetOutputFormatOption calls instead of freeing/recreating the formatoption list from scratch. That will overwrite an existing key and keep the existing ones.
Fix memory leak when loading FORMATOPTIONS (#5149)
closing, see #5255