Date: Thu, 18 Sep 1997 15:46:19 -0600 (MDT) From: Nate Williams <nate@mt.sri.com> To: Terry Lambert <tlambert@primenet.com> Cc: nate@mt.sri.com (Nate Williams), phk@critter.freebsd.dk, gram@cdsec.com, hackers@freebsd.org Subject: Re: Bug in malloc/free (was: Memory leak in getservbyXXX?) Message-ID: <199709182146.PAA14637@rocky.mt.sri.com> In-Reply-To: <199709182140.OAA15537@usr03.primenet.com> References: <199709181912.NAA13699@rocky.mt.sri.com> <199709182140.OAA15537@usr03.primenet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> > > > [ 'hangs' in malloc due to memory over-write causing circular lists ] > > > 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. > 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? Nate
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709182146.PAA14637>