Skip to content

Commit

Permalink
msDrawTextIM(): fix leak in error code path (CID 1503248)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jul 8, 2021
1 parent d61fbc1 commit 7cb6091
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mapimagemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,19 @@ int msDrawTextIM(mapObj *map, imageObj* img, pointObj labelPnt, char *string, la
int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format )

{
FILE *stream_to_free = NULL;
FILE *stream;
char workbuffer[5000];

DEBUG_IF printf("msSaveImageIM\n<BR>");

if(filename != NULL && strlen(filename) > 0) {
stream = fopen(filename, "wb");
if(!stream) {
stream_to_free = fopen(filename, "wb");
if(!stream_to_free) {
msSetError(MS_IOERR, "(%s)", "msSaveImage()", filename);
return(MS_FAILURE);
}
stream = stream_to_free;
} else { /* use stdout */

#ifdef _WIN32
Expand Down Expand Up @@ -696,10 +698,11 @@ int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format )
} else {
msSetError(MS_MISCERR, "Unknown output image type driver: %s.",
"msSaveImage()", format->driver );
if(stream_to_free != NULL) fclose(stream_to_free);
return(MS_FAILURE);
}

if(filename != NULL && strlen(filename) > 0) fclose(stream);
if(stream_to_free != NULL) fclose(stream_to_free);
return(MS_SUCCESS);
}

Expand Down

0 comments on commit 7cb6091

Please sign in to comment.