% MagickCore Memory Allocation Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1998 %
% %
% %
-% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
struct _MemoryInfo
{
char
- filename[MaxTextExtent];
+ filename[MagickPathExtent];
VirtualMemoryType
type;
memory=memory_methods.acquire_memory_handler(size == 0 ? 1UL : size);
#else
if (memory_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&memory_semaphore);
+ ActivateSemaphoreInfo(&memory_semaphore);
if (free_segments == (DataSegmentInfo *) NULL)
{
LockSemaphoreInfo(memory_semaphore);
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
(void) ResetMagickMemory(memory_info,0,sizeof(*memory_info));
memory_info->length=length;
- memory_info->signature=MagickSignature;
+ memory_info->signature=MagickCoreSignature;
if (AcquireMagickResource(MemoryResource,length) != MagickFalse)
{
memory_info->blob=AcquireAlignedMemory(1,length);
else
RelinquishMagickResource(MapResource,length);
}
- if (memory_info->blob == NULL)
+ if ((memory_info->blob == NULL) &&
+ (AcquireMagickResource(DiskResource,length) != MagickFalse))
{
int
file;
Anonymous memory mapping failed, try file-backed memory mapping.
*/
file=AcquireUniqueFileResource(memory_info->filename);
- if (file != -1)
+ if (file == -1)
+ RelinquishMagickResource(DiskResource,length);
+ else
{
- if ((lseek(file,length-1,SEEK_SET) >= 0) && (write(file,"",1) == 1))
+ if ((lseek(file,length-1,SEEK_SET) < 0) || (write(file,"",1) != 1))
+ RelinquishMagickResource(DiskResource,length);
+ else
{
- memory_info->blob=MapBlob(file,IOMode,0,length);
- if (memory_info->blob != NULL)
+ if (AcquireMagickResource(MapResource,length) == MagickFalse)
+ RelinquishMagickResource(DiskResource,length);
+ else
{
- memory_info->type=MapVirtualMemory;
- (void) AcquireMagickResource(MapResource,length);
+ memory_info->blob=MapBlob(file,IOMode,0,length);
+ if (memory_info->blob != NULL)
+ memory_info->type=MapVirtualMemory;
+ else
+ {
+ RelinquishMagickResource(MapResource,length);
+ RelinquishMagickResource(DiskResource,length);
+ }
}
}
(void) close(file);
i;
if (memory_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&memory_semaphore);
+ ActivateSemaphoreInfo(&memory_semaphore);
LockSemaphoreInfo(memory_semaphore);
- UnlockSemaphoreInfo(memory_semaphore);
for (i=0; i < (ssize_t) memory_pool.number_segments; i++)
if (memory_pool.segments[i]->mapped == MagickFalse)
memory_methods.destroy_memory_handler(
memory_pool.segments[i]->length);
free_segments=(DataSegmentInfo *) NULL;
(void) ResetMagickMemory(&memory_pool,0,sizeof(memory_pool));
- DestroySemaphoreInfo(&memory_semaphore);
+ UnlockSemaphoreInfo(memory_semaphore);
+ RelinquishSemaphoreInfo(&memory_semaphore);
#endif
}
\f
MagickExport void *GetVirtualMemoryBlob(const MemoryInfo *memory_info)
{
assert(memory_info != (const MemoryInfo *) NULL);
- assert(memory_info->signature == MagickSignature);
+ assert(memory_info->signature == MagickCoreSignature);
return(memory_info->blob);
}
\f
MagickExport MemoryInfo *RelinquishVirtualMemory(MemoryInfo *memory_info)
{
assert(memory_info != (MemoryInfo *) NULL);
- assert(memory_info->signature == MagickSignature);
+ assert(memory_info->signature == MagickCoreSignature);
if (memory_info->blob != (void *) NULL)
switch (memory_info->type)
{
memory_info->blob=NULL;
RelinquishMagickResource(MapResource,memory_info->length);
if (*memory_info->filename != '\0')
- (void) RelinquishUniqueFileResource(memory_info->filename);
+ {
+ (void) RelinquishUniqueFileResource(memory_info->filename);
+ RelinquishMagickResource(DiskResource,memory_info->length);
+ }
break;
}
case UnalignedVirtualMemory:
break;
}
}
- memory_info->signature=(~MagickSignature);
+ memory_info->signature=(~MagickCoreSignature);
memory_info=(MemoryInfo *) RelinquishAlignedMemory(memory_info);
return(memory_info);
}