From cca91aa1861818342e3d072bb0fad7dc4ffac24a Mon Sep 17 00:00:00 2001 From: Cristy Date: Sat, 30 Sep 2017 09:34:33 -0400 Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/790 --- MagickCore/memory-private.h | 15 +++++++++++++++ MagickCore/opencl.c | 5 +++-- MagickCore/registry.c | 5 ++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/MagickCore/memory-private.h b/MagickCore/memory-private.h index 0390cbe65..bea3d6d77 100644 --- a/MagickCore/memory-private.h +++ b/MagickCore/memory-private.h @@ -22,6 +22,7 @@ extern "C" { #endif +#include "MagickCore/exception.h" #if defined(__powerpc__) # define CACHE_LINE_SIZE 128 @@ -45,6 +46,20 @@ extern "C" { MagickExport MagickBooleanType HeapOverflowSanityCheck(const size_t,const size_t) magick_alloc_sizes(1,2); +static inline void *AcquireCriticalMemory(const size_t size) +{ + register void + *memory; + + /* + Fail if memory request cannot be fulfilled. + */ + memory=AcquireMagickMemory(size); + if (memory == (void *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + return(memory); +} + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/MagickCore/opencl.c b/MagickCore/opencl.c index bee3a43e3..bf27dea02 100644 --- a/MagickCore/opencl.c +++ b/MagickCore/opencl.c @@ -61,6 +61,7 @@ #include "MagickCore/layer.h" #include "MagickCore/mime-private.h" #include "MagickCore/memory_.h" +#include "MagickCore/memory-private.h" #include "MagickCore/monitor.h" #include "MagickCore/montage.h" #include "MagickCore/morphology.h" @@ -323,7 +324,7 @@ static const char *GetOpenCLCacheDirectory() if (status != MagickFalse) { - temp=(char*) AcquireMagickMemory(strlen(path)+1); + temp=(char*) AcquireCriticalMemory(strlen(path)+1); CopyMagickString(temp,path,strlen(path)+1); } home=DestroyString(home); @@ -3234,4 +3235,4 @@ MagickExport void SetOpenCLKernelProfileEnabled( magick_unreferenced(device); magick_unreferenced(value); } -#endif \ No newline at end of file +#endif diff --git a/MagickCore/registry.c b/MagickCore/registry.c index 4cc676025..2e159f7f8 100644 --- a/MagickCore/registry.c +++ b/MagickCore/registry.c @@ -46,6 +46,7 @@ #include "MagickCore/image.h" #include "MagickCore/list.h" #include "MagickCore/memory_.h" +#include "MagickCore/memory-private.h" #include "MagickCore/registry.h" #include "MagickCore/registry-private.h" #include "MagickCore/splay-tree.h" @@ -514,9 +515,7 @@ MagickExport MagickBooleanType SetImageRegistry(const RegistryType type, } if (clone_value == (void *) NULL) return(MagickFalse); - registry_info=(RegistryInfo *) AcquireMagickMemory(sizeof(*registry_info)); - if (registry_info == (RegistryInfo *) NULL) - ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + registry_info=(RegistryInfo *) AcquireCriticalMemory(sizeof(*registry_info)); (void) ResetMagickMemory(registry_info,0,sizeof(*registry_info)); registry_info->type=type; registry_info->value=clone_value; -- 2.40.0