After a while malloc returns null
Posted: 2010-03-30T01:21:25-07:00
Is there any reason why would malloc return null and then even MapBlob function returns null.
This all happens in method OpenPixelCache in cache.c on line 3784.
I was wondering about this code:
I have a question regarding this piece of code:
Namely, if malloc returns null then this executes : cache_info->pixels=source_info.pixels; Should we return MagickTrue in this case also?
So, instead of the code above should it be more like this:
This is pretty important, because if we don't return MagickTrue the file is being cached on disk and I really want to avoid that.
I have 4GB of RAM, my program constantly consumes only 700MB of memory so I don't understand why would malloc return NULL. I have WindowsXP SP3 with latest updates.
One last thing, I have found a bunch of memory leaks using Trial version of Insure++ when doing resizing of an image. I can not give you the whole source code of this program but I will try and make some small example where this happens.
Thank you for your time and effort.
Cheers.
This all happens in method OpenPixelCache in cache.c on line 3784.
I was wondering about this code:
Code: Select all
status=AcquireMagickResource(AreaResource,cache_info->length);
length=number_pixels*(sizeof(PixelPacket)+sizeof(IndexPacket));
if ((status != MagickFalse) && (length == (MagickSizeType) ((size_t) length)))
{
status=AcquireMagickResource(MemoryResource,cache_info->length);
if (((cache_info->type == UndefinedCache) && (status != MagickFalse)) ||
(cache_info->type == MemoryCache))
{
AcquirePixelCachePixels(cache_info);
if (cache_info->pixels == (PixelPacket *) NULL)
cache_info->pixels=source_info.pixels;
else
{
/*
Create memory pixel cache.
*/
if (image->debug != MagickFalse)
{
(void) FormatMagickSize(cache_info->length,format);
(void) FormatMagickString(message,MaxTextExtent,
"open %s (%s memory, %lux%lu %s)",cache_info->filename,
cache_info->mapped != MagickFalse ? "anonymous" : "heap",
cache_info->columns,cache_info->rows,format);
(void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",
message);
}
cache_info->storage_class=image->storage_class;
cache_info->colorspace=image->colorspace;
cache_info->type=MemoryCache;
cache_info->indexes=(IndexPacket *) NULL;
if (cache_info->active_index_channel != MagickFalse)
cache_info->indexes=(IndexPacket *) (cache_info->pixels+
number_pixels);
if (source_info.storage_class != UndefinedClass)
{
status|=ClonePixelCache(cache_info,&source_info,exception);
RelinquishPixelCachePixels(&source_info);
}
return(MagickTrue);
}
}
RelinquishMagickResource(MemoryResource,cache_info->length);
}
Code: Select all
return(MagickTrue);
}
}
RelinquishMagickResource(MemoryResource,cache_info->length);
So, instead of the code above should it be more like this:
Code: Select all
}
return(MagickTrue);
}
RelinquishMagickResource(MemoryResource,cache_info->length);
I have 4GB of RAM, my program constantly consumes only 700MB of memory so I don't understand why would malloc return NULL. I have WindowsXP SP3 with latest updates.
One last thing, I have found a bunch of memory leaks using Trial version of Insure++ when doing resizing of an image. I can not give you the whole source code of this program but I will try and make some small example where this happens.
Thank you for your time and effort.
Cheers.