Set TIFF error handler in RegisterTIFFImage()
diff --git a/coders/tiff.c b/coders/tiff.c
index 44ede50..3937e85 100755
--- a/coders/tiff.c
+++ b/coders/tiff.c
@@ -203,6 +203,10 @@
static SemaphoreInfo
*tiff_semaphore = (SemaphoreInfo *) NULL;
+static TIFFErrorHandler
+ error_handler,
+ warning_handler;
+
static volatile MagickBooleanType
instantiate_key = MagickFalse;
@@ -1102,10 +1106,6 @@
TIFF
*tiff;
- TIFFErrorHandler
- error_handler,
- warning_handler;
-
TIFFMethodType
method;
@@ -1152,15 +1152,11 @@
return((Image *) NULL);
}
(void) SetMagickThreadValue(tiff_exception,exception);
- error_handler=TIFFSetErrorHandler(TIFFErrors);
- warning_handler=TIFFSetWarningHandler(TIFFWarnings);
tiff=TIFFClientOpen(image->filename,"rb",(thandle_t) image,TIFFReadBlob,
TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob,
TIFFUnmapBlob);
if (tiff == (TIFF *) NULL)
{
- (void) TIFFSetWarningHandler(warning_handler);
- (void) TIFFSetErrorHandler(error_handler);
image=DestroyImageList(image);
return((Image *) NULL);
}
@@ -2105,8 +2101,6 @@
break;
}
} while (status != MagickFalse);
- (void) TIFFSetWarningHandler(warning_handler);
- (void) TIFFSetErrorHandler(error_handler);
TIFFClose(tiff);
TIFFReadPhotoshopLayers(image,image_info,exception);
if (image_info->number_scenes != 0)
@@ -2254,6 +2248,8 @@
{
if (CreateMagickThreadKey(&tiff_exception,NULL) == MagickFalse)
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ error_handler=TIFFSetErrorHandler(TIFFErrors);
+ warning_handler=TIFFSetWarningHandler(TIFFWarnings);
#if defined(MAGICKCORE_HAVE_TIFFMERGEFIELDINFO) && defined(MAGICKCORE_HAVE_TIFFSETTAGEXTENDER)
if (tag_extender == (TIFFExtendProc) NULL)
tag_extender=TIFFSetTagExtender(TIFFTagExtender);
@@ -2381,6 +2377,8 @@
#endif
if (DeleteMagickThreadKey(tiff_exception) == MagickFalse)
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ (void) TIFFSetWarningHandler(warning_handler);
+ (void) TIFFSetErrorHandler(error_handler);
instantiate_key=MagickFalse;
}
UnlockSemaphoreInfo(tiff_semaphore);
@@ -3115,10 +3113,6 @@
TIFF
*tiff;
- TIFFErrorHandler
- error_handler,
- warning_handler;
-
TIFFInfo
tiff_info;
@@ -3149,8 +3143,6 @@
if (status == MagickFalse)
return(status);
(void) SetMagickThreadValue(tiff_exception,exception);
- error_handler=TIFFSetErrorHandler((TIFFErrorHandler) TIFFErrors);
- warning_handler=TIFFSetWarningHandler((TIFFErrorHandler) TIFFWarnings);
endian_type=UndefinedEndian;
option=GetImageOption(image_info,"tiff:endian");
if (option != (const char *) NULL)
@@ -3179,11 +3171,7 @@
TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob,
TIFFUnmapBlob);
if (tiff == (TIFF *) NULL)
- {
- (void) TIFFSetWarningHandler(warning_handler);
- (void) TIFFSetErrorHandler(error_handler);
- return(MagickFalse);
- }
+ return(MagickFalse);
scene=0;
debug=IsEventLogging();
(void) debug;
@@ -3942,8 +3930,6 @@
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
- (void) TIFFSetWarningHandler(warning_handler);
- (void) TIFFSetErrorHandler(error_handler);
TIFFClose(tiff);
return(MagickTrue);
}