From owner-freebsd-hackers Thu Sep 18 09:49:45 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id JAA18609 for hackers-outgoing; Thu, 18 Sep 1997 09:49:45 -0700 (PDT) Received: from citadel.cdsec.com (citadel.cdsec.com [192.96.22.18]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id JAA18595 for ; Thu, 18 Sep 1997 09:49:31 -0700 (PDT) Received: (from nobody@localhost) by citadel.cdsec.com (8.8.5/8.6.9) id SAA17690; Thu, 18 Sep 1997 18:54:35 +0200 (SAT) Received: by citadel via recvmail id 17688; Thu Sep 18 18:53:52 1997 by gram.cdsec.com (8.8.5/8.8.5) id SAA00548; Thu, 18 Sep 1997 18:40:58 +0200 (SAT) From: Graham Wheeler Message-Id: <199709181640.SAA00548@cdsec.com> Subject: Re: Bug in malloc/free (was: Memory leak in getservbyXXX?) To: phk@critter.freebsd.dk (Poul-Henning Kamp) Date: Thu, 18 Sep 1997 18:40:57 +0200 (SAT) Cc: gram@gram.cdsec.com (Graham Wheeler), hackers@freebsd.org In-Reply-To: <10531.874599844@critter.freebsd.dk> from "Poul-Henning Kamp" at Sep 18, 97 06:24:04 pm X-Mailer: ELM [version 2.4 PL25-h4.1] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Howdy > >i.e. the size is stored both immediately preceding and immediately > >following the useable space. As part of the consistency checking, > >these two sizes are compared and should match. This should catch almost > >all small overruns or underruns, and abort the process. So this > >malloc should be less tolerant of bugs in my code than pkhmalloc is, > >rather than more tolerant, > > again: depends. Fair enough - I assume then that the reason your prior example had padding was because you round allocations up to multiples of four bytes, rather than always adding padding to be `fault-tolerant'. > >Can you offer an explanation as to why the process never returns from > >the call to malloc, nor does it abort? This seems to indicate an infinite > >loop. Not having delved too deeply into your code, I can only speculate > >that the linked list is being made circular, so the process is in an > >infinite, looping traversal. Perhaps that is a check that can be added; > >namely that walking the list must always proceed forward, never backward > >(assuming that the list is kept in sequential order). It is interesting to note that this looping is almost always what happens - it is very rare that the process actually aborts. It seems strange that the bahaviour is so consistent, especially as the stack backtraces are in very different parts of my own code, and the application itself is pretty non-deterministic, being I/O event-driven. This, together with the fact that the problem only started when we moved to from FreeBSD 2.1 to 2.2.2, is why I suggested that the bug may be in the malloc code. Let me state quite clearly though that this is a suggestion, certainly not an accusation. I'm just running out of things to suspect... > This is about the only way you could get it to loop I think. That means > that somebody wrote to memory malloc hadn't passed them (ie: your code). Well, someone's code ;-). > This would indicate a bug of the class where memory is written to after > being free()'ed, a kind of bug which phkmalloc makes no attempt to catch. Nor should it, that would be a performance sacrifice. That's why I linked with a debug library. I'll check once again for this, but doubt I'll find anything - I'm quite meticulous about zeroing pointers after freeing them, unless the variable in question goes out of scope immediately afterwards. I *have* to meticulous - I'm the person who gets the flack when things go wrong, and believe me, you don't want 5000 pissed off people screaming at you that they can't surf the web... If the process is still running fine tomorrow morning, I am going to try a version linked with the alternative libmalloc but using the non-debug version; this could also be interesting. -- Dr Graham Wheeler E-mail: gram@cdsec.com Citadel Data Security Phone: +27(21)23-6065/6/7 Internet/Intranet Network Specialists Mobile: +27(83)-253-9864 Firewalls/Virtual Private Networks Fax: +27(21)24-3656 Data Security Products WWW: http://www.cdsec.com/