Mail Archives: djgpp/1999/08/21/19:44:27
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 -