bug-gnu-chess
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leak in Chess 5.00, 5.03 related to InitHashTable()


From: Lukas Geyer
Subject: Re: Memory leak in Chess 5.00, 5.03 related to InitHashTable()
Date: 14 Mar 2002 13:23:50 +0100

address@hidden (Sven Coenye) writes:

> I would like to report a memory leak in GNU Chess 5.03 and below.
> 
> The InitHashTable function in file init.c can be called at will through 
> the 'hashsize' command. However, InitHashTable() fails to free the two 
> blocks of memory that were allocated for the pawn tables on the previous 
> call. I have been able to verify this with memwatch and its logs report 
> that 12288 bytes of memory are lost with each invocation of 
> InitHashTable() (using an unmodified common.h).
> 
> There is a second problem in InitHashTable() as well. As written, the 
> function attempts to free memory that was never allocated. This may 
> become a partability issue on platforms where variables are not 
> automatically zeroed out when they are created, or where free() doesn't 
> work as advertised.

Thanks, great bug hunting. :) Well, freeing unallocated memory is a
serious bug in any case, whether it crashes or not. (We have just seen 
that zlib disaster.)

> And finally, the PawnTab memory that was allocated last never gets freed 
> when GNUChess exits. There are free() calls for allocated HashTab memory 
> at the end of main(), but none for PawnTab.

This is not really as serious as the two bugs above but it is bad
style in any case. (If an OS does not free process resources when the
process dies, I would consider that OS broken, but one never knows...)

> I have attached patched versions of GNU Chess 5.03 main.c and init.c to 
> address these issues.
> 
> Hoping this is useful,

Definitely it is. Thanks a lot.

Best regards,
Lukas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]