cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/21/19:44:27

Sender: nate AT cartsys DOT com
Message-ID: <37BF31BC.9BC77588@cartsys.com>
Date: Sat, 21 Aug 1999 16:09:48 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.12pre4 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: free(void *) is driving me nuts!!!
References: <379E3222 DOT CA7C7283 AT go DOT ro> <37BDCEBA DOT 194CF551 AT cartsys DOT com> <37A0BF41 DOT B7061F9F AT go DOT ro>
Reply-To: djgpp AT delorie DOT com

Radu Georgescu aka skoola wrote:
> 
> > > is there any known problem with free()??
> > > my programm crashes sometimes and there is no crash if i'm removeing the
> > > free calls.
> > > i'm using some v2 distribution and pgcc.
> >
> > Most likely, this is your bug.  Things like writing an array out of
> > bounds corrupt some of malloc's internal data, which can make it crash.
> >
> 
> you meen malloc has some internal data?

Yes.

> i think it just calls some dpmi service and if you pass some good pointer to
> free it should work.

It doesn't.  Read the source if you like, but malloc gets memory from
the DPMI server in large chunks, because that's faster and more
efficient.  Then it breaks them up into pieces to satisfy your
allocations of arbitrary size.  Info like the size of the block and the
location of the next one are kept beyond the boundaries of the block it
gives you (so if you allocate a 32 byte block, it might take 40 and keep
its stuff in the extra 8.)  If you mess up this info, malloc will
happily believe it (it does very little sanity checking, for speed) and
often die horribly.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019