Code: Select all
if (~string_info->length >= (MaxTextExtent-1))
string_info->datum=(unsigned char *) AcquireQuantumMemory(
string_info->length+MaxTextExtent,sizeof(*string_info->datum));
Shouldn't BlobToStringInfo() be passing the length parameter directly to AcquireStringInfo() so it can allocate the datum at the correct size instead of trying to allocate it itself? This would not only fix the memory leak but also get rid of some ugly copy-pasta. Additionally, the code that is checking whether or not the datum was allocated can be removed since AcquireStringInfo() already checks and throws an exception if it fails.
The current implementation of BlobToStringInfo() looks like this:
Code: Select all
MagickExport StringInfo *BlobToStringInfo(const void *blob,const size_t length)
{
StringInfo
*string_info;
string_info=AcquireStringInfo(0);
string_info->length=length;
if (~string_info->length >= (MaxTextExtent-1))
string_info->datum=(unsigned char *) AcquireQuantumMemory(
string_info->length+MaxTextExtent,sizeof(*string_info->datum));
if (string_info->datum == (unsigned char *) NULL)
{
string_info=DestroyStringInfo(string_info);
return((StringInfo *) NULL);
}
if (blob != (const void *) NULL)
(void) memcpy(string_info->datum,blob,length);
return(string_info);
}
Code: Select all
MagickExport StringInfo *BlobToStringInfo(const void *blob,const size_t length)
{
StringInfo
*string_info;
string_info=AcquireStringInfo(length);
if (blob != (const void *) NULL)
(void) memcpy(string_info->datum,blob,length);
return(string_info);
}