From 1ae02d5783ffdcdceba7c2f38ae947cd461ff9b6 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sat, 18 Nov 2023 16:54:04 -0500 Subject: [PATCH] improve I/O exception handling --- magick/blob.c | 7 +++---- magick/constitute.c | 6 ++++-- magick/feature.c | 3 ++- magick/image.c | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/magick/blob.c b/magick/blob.c index e47482cf9..f407c1338 100644 --- a/magick/blob.c +++ b/magick/blob.c @@ -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); @@ -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 @@ -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); diff --git a/magick/constitute.c b/magick/constitute.c index 32212a662..adc4f55de 100644 --- a/magick/constitute.c +++ b/magick/constitute.c @@ -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) && @@ -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); diff --git a/magick/feature.c b/magick/feature.c index 6b9d76037..d376b5a7d 100644 --- a/magick/feature.c +++ b/magick/feature.c @@ -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)); } diff --git a/magick/image.c b/magick/image.c index 03743d69e..ed7c842c7 100644 --- a/magick/image.c +++ b/magick/image.c @@ -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);