Date: Sun, 5 Apr 1998 21:40:20 -0700 (PDT) Message-Id: <199804060440.VAA02993@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: obremski AT nwrain DOT com, djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: malloc errors Precedence: bulk At 02:01 4/5/1998 +0000, Neil & Joey Obremski wrote: >I've had problems in some of my programs using 'new' which of course >comes out using malloc anyway. I found this out quickly when a lot of >my programs kept crashing and gdb kept saying malloc did it ;) The traceback should show that `malloc' was called by `__builtin_new', which should have tipped you off. >I don't know if there's a problem with malloc in djgpp or not, but it >certainly doesn't work 100% correctly when I use it. Some of my >programs I spent hours debugging only to find that if I pass a >constant added to a variable to my allocation function (Alloc I called >it, wow pretty original =) malloc works fine, otherwise it doesn't. 99% chance, this is your bug. `malloc' maintains some fairly delicate data structures keeping track of what's allocated, and messing them up can mean crashes. In your case, you're lucky it crashes; makes it a lot easier to debug than when it just corrupts some other piece of memory. Watch out for the following: * `free'ing a pointer not obtained from `malloc' * `free'ing a pointer twice * Overwriting the bounds of a `malloc'ed block There is a package called MSS which can help catch these; look in v2tk/ on Simtelnet. Nate Eldredge eldredge AT ap DOT net