Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Sep 1997 22:07:47 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        nate@mt.sri.com (Nate Williams)
Cc:        tlambert@primenet.com, nate@mt.sri.com, phk@critter.freebsd.dk, gram@cdsec.com, hackers@freebsd.org
Subject:   Re: Bug in malloc/free (was: Memory leak in getservbyXXX?)
Message-ID:  <199709182207.PAA17437@usr03.primenet.com>
In-Reply-To: <199709182146.PAA14637@rocky.mt.sri.com> from "Nate Williams" at Sep 18, 97 03:46:19 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> > 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.
> 
> Easy enough.
> 
> > Now you must find the length of the loop.  You save the current
> > pointer, and traverse until you see it again, counting.  This count
> > is the length of the loop.
> 
> Naw, you keep track of how many objects are on the list by
> incrementing/decrementing when you add/remove objects on the list.
> Otherwise, it's much too slow, and adding/subtracting one is a very
> minor hit.  And, your solution assumes that the loop is indeed circular,
> which it may/may not be.

Soory, I wasn't clear.  Of course you track the number of elements in
the list like that.  The intent of the second set of tasks is to:

1)	Detect the loop during traversal, which is when the hang
	will occur.
2)	Once you detect a loop, spit out the most likely culprits;
	these are the allocation immediately prior to the loop, the
	first and second entries in the loop, and the last entry (it's
	linked to the first).


> > If the pointer traverses to itself, this is a simpler case
> 
> In my solution, it's still found, since you have *one* element, and if
> yo traverse twice, you're in a circular loop.
> 
> [ Overly complicated solution deleted ]
> 
> Why make it hard when it can be easy?

The point is to detect the addresses of the objects which when
manipulated resulted in the loop in the first place.  Without
that information, you;ll only know you have a loop.  Big deal, I
can tell I have a loop when it hangs in malloc() forever.  8-).


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



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