Date: Mon, 22 Sep 1997 22:07:57 +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: <19970922220757.30317@bitbox.follo.net> In-Reply-To: <199709221941.MAA18135@usr06.primenet.com>; from Terry Lambert on Mon, Sep 22, 1997 at 07:41:55PM %2B0000 References: <19970922113306.60050@bitbox.follo.net> <199709221941.MAA18135@usr06.primenet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Sep 22, 1997 at 07:41:55PM +0000, Terry Lambert wrote: > Seeing that the list has looped does not guarantee that you know > where the last valid entry, or first invalid entry, exists. Agreed. And neither do anything else, except storing extra copies of all pointers somewhere where they can't be overwritten. > I don't even agree that your method actually finds the list loop, unless > you somhow guarantee that the loop goes back to the had such that your > pointer comparison is valid. (I assume you mean 'head' where you write 'had') Read the code again. It work by having two pointers walking the list, one fast and one slow. When the slow pointer intersect with the fast pointer, you know that you have a loop. And the slow pointer _will_ intersect the fast one if you have a loop and the datastructure isn't modified during the execution of your code - it follow the exact same set of links as the fast one, just at half the speed. As for the advanced diagonstics you want - sure, they look nice. However, I've implemented this kind of diagnostics before, and as long as I've exposed the invariant routine so it can be run at any point in the program, I've never needed or had benefit from them. I've found sprinkling the program with invariant checks at strategic points to be much more effective at exposing problems. Eivind.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970922220757.30317>