Skip to content

Commit

Permalink
improve I/O exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Nov 18, 2023
1 parent 10cb1f0 commit 1ae02d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions magick/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,6 @@ MagickExport unsigned char *ImageToBlob(const ImageInfo *image_info,
(void) FormatLocaleString(image->filename,MagickPathExtent,
"%s:%s",image->magick,unique);
status=WriteImage(blob_info,image);
(void) CloseBlob(image);
(void) fclose(blob_info->file);
if (status == MagickFalse)
InheritException(exception,&image->exception);
Expand Down Expand Up @@ -2042,8 +2041,9 @@ MagickExport unsigned char *ImagesToBlob(const ImageInfo *image_info,
blob=(unsigned char *) ResizeQuantumMemory(blob,*length+1,
sizeof(unsigned char));
}
else if (status == MagickFalse)
blob_info->blob=RelinquishMagickMemory(blob_info->blob);
else
if (status == MagickFalse)
blob_info->blob=RelinquishMagickMemory(blob_info->blob);
}
}
else
Expand Down Expand Up @@ -2072,7 +2072,6 @@ MagickExport unsigned char *ImagesToBlob(const ImageInfo *image_info,
(void) FormatLocaleString(filename,MagickPathExtent,"%s:%s",
images->magick,unique);
status=WriteImages(blob_info,images,filename,exception);
(void) CloseBlob(images);
(void) fclose(blob_info->file);
if (status == MagickFalse)
InheritException(exception,&images->exception);
Expand Down
6 changes: 4 additions & 2 deletions magick/constitute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,8 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
(void) AcquireUniqueFilename(image->filename);
temporary=MagickTrue;
}
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
}
}
if ((magick_info != (const MagickInfo *) NULL) &&
Expand Down Expand Up @@ -1335,7 +1336,8 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
(void) RelinquishUniqueFileResource(write_info->filename);
status=ImageToFile(image,write_info->filename,exception);
}
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
(void) RelinquishUniqueFileResource(image->filename);
(void) CopyMagickString(image->filename,write_info->filename,
MaxTextExtent);
Expand Down
3 changes: 2 additions & 1 deletion magick/feature.c
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,8 @@ static Image *RenderHoughLines(const ImageInfo *image_info,const size_t columns,
}
(void) DrawImage(image,draw_info);
draw_info=DestroyDrawInfo(draw_info);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
image=DestroyImageList(image);
return(GetFirstImageInList(image));
}

Expand Down
3 changes: 2 additions & 1 deletion magick/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -3000,7 +3000,8 @@ MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
*/
*filename='\0';
status=ImageToFile(image,filename,exception);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
{
(void) RelinquishUniqueFileResource(filename);
Expand Down

0 comments on commit 1ae02d5

Please sign in to comment.