Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Sep 1997 11:33:06 +0200
From:      Eivind Eklund <eivind@bitbox.follo.net>
To:        Terry Lambert <tlambert@primenet.com>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Bug in malloc/free (was: Memory leak in getservbyXXX?)
Message-ID:  <19970922113306.60050@bitbox.follo.net>
In-Reply-To: <199709220555.WAA15014@usr07.primenet.com>; from Terry Lambert on Mon, Sep 22, 1997 at 05:55:09AM %2B0000
References:  <199709211735.TAA20824@bitbox.follo.net> <199709220555.WAA15014@usr07.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Sep 22, 1997 at 05:55:09AM +0000, Terry Lambert wrote:
> > > You could determine that a list is circular by maintaining a count of
> > > the number of objects that are supposed to be on the freelist.  Then
> > > you count the number of "next" traversals which occur, and when it
> > > excceeds the count of how many are supposed to be there, then you
> > > know you have a problem.
> > 
> > Why make it this hard, and subject to trashing of the list count?  The
> > following  code will check for a circular loop (no knowledge of length
> > required) for a single-linked list:
> 
> Because we want to locate the erroneous entries, and the entries most
> likely to have been trashed to create the loop in the first place, in
> order to report them (and hopefully get the probem corrected).
> 
> This whole thread has really been about finding problems in code using
> the memory allocation code.

So?  I can't see that you need to count to do this.  The list itself
is enough, even though the counter in itself might be information you
would like to have.  You just don't need it for actually finding the
loop, the loop length or where the loop start; you cut the part which
actually described this, the code was just a better way of
implementing the list verificiation itself, and not to be taken
verbatim.  abort() was just to make it obvious where you saw that the
list had looped.

Eivind.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970922113306.60050>