Re: Memory leak in gif.c?

Bob Friesenhahn <[email protected]> Mon, 15 Nov 2004 16:28:12 -0600 (CST)
Newsgroups gmane.comp.video.graphicsmagick.bugs
Message-ID <[email protected]>
These look like leaks to me.  The memory leak fixed for 1.1.4 was in 
a memory allocation error path, similar to these.

Probably the argument used at the time the code was written was that 
if a small/fixed-size memory allocation fails, the program should exit 
since it is pointless to continue.  Freeing any allocated memory will 
help though since it provides the program with a chance to acquire 
enough memory to properly handle/report the error.

Bob

On Mon, 15 Nov 2004, Glenn Randers-Pehrson wrote:

> It looks as though the following code from gif.c (line 497) ought to free
> packet, hash_code, hash_prefix, and hash_suffix when it detects
> an Alloc failure in one of them.
>
>  packet=MagickAllocateMemory(unsigned char *,256);
>  hash_code=MagickAllocateMemory(short *,MaxHashTable*sizeof(short));
>  hash_prefix=MagickAllocateMemory(short *,MaxHashTable*sizeof(short));
>  hash_suffix=MagickAllocateMemory(unsigned char *,MaxHashTable);
>  if ((packet == (unsigned char *) NULL) || (hash_code == (short *) NULL) ||
>      (hash_prefix == (short *) NULL) ||
>      (hash_suffix == (unsigned char *) NULL))
>    return(MagickFail);
>
> Similar problem at line 1240:
>
>  global_colormap=MagickAllocateMemory(unsigned char *,768);
>  colormap=MagickAllocateMemory(unsigned char *,768);
>  if ((global_colormap == (unsigned char *) NULL) ||
>      (colormap == (unsigned char *) NULL))
>    ThrowWriterException(ResourceLimitError,MemoryAllocationFailed,image);
>
> I have not run any tests to see if leakage actually occurs.
>
> Glenn
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: InterSystems CACHE
> FREE OODBMS DOWNLOAD - A multidimensional database that combines
> robust object and relational technologies, making it a perfect match
> for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
> _______________________________________________
> Graphicsmagick-bugs mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/graphicsmagick-bugs
>

======================================
Bob Friesenhahn
[email protected]
http://www.simplesystems.org/users/bfriesen


-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8