From owner-freebsd-hackers Mon Sep 22 02:33:17 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id CAA28951 for hackers-outgoing; Mon, 22 Sep 1997 02:33:17 -0700 (PDT) Received: from bitbox.follo.net (bitbox.follo.net [194.198.43.36]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id CAA28946 for ; Mon, 22 Sep 1997 02:33:12 -0700 (PDT) Received: (from eivind@localhost) by bitbox.follo.net (8.8.6/8.8.6) id LAA27367; Mon, 22 Sep 1997 11:33:06 +0200 (MET DST) Message-ID: <19970922113306.60050@bitbox.follo.net> Date: Mon, 22 Sep 1997 11:33:06 +0200 From: Eivind Eklund To: Terry Lambert Cc: hackers@FreeBSD.ORG Subject: Re: Bug in malloc/free (was: Memory leak in getservbyXXX?) References: <199709211735.TAA20824@bitbox.follo.net> <199709220555.WAA15014@usr07.primenet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.69e In-Reply-To: <199709220555.WAA15014@usr07.primenet.com>; from Terry Lambert on Mon, Sep 22, 1997 at 05:55:09AM +0000 Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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.