Re: double free

From: jacob navia (jacob_at_jacob.remcomp.fr)
Date: 07/01/04


Date: Thu, 1 Jul 2004 21:50:57 +0200


"weaselboy1976" <weaselboy1976@yahoo.com> a écrit dans le message de
news:c76c305f.0407011027.5749e6d2@posting.google.com...
> Hello
>
> Does anyone know of a good website that actually describes and
> demonstrates WHY freeing a pointer more than once is a problem. I'm
> specifically interested in what the ill effects are.
>
> Also, if you know of any really good books that describe everything
> about memory in a c program ...
>
> Thanks in advance!

I assume that in all implementations where
free checks if the address is *already* in the free list
nothing serious can happen.

In all others, there is a block twice in the free list,
that can later be allocated twice to the program
again. Unrelated data items will have the same
address and when you write into one you corrupt the
other.

This can go unnoticed for years or provoke
a crash immediately. It depends on which blocks
are used where, etc.

Depending on the algorithm used by free, the
free list could become corrupted when inserting
a block that is already there.

To avoid this, and other catastrophes that may fall into you
use a garbage collector. The machine takes care of
freeing blocks regularly.

lcc-win32 offers a gc with its runtime.



Relevant Pages

  • Re: free()
    ... freeing a goat will have to deal with this. ... going to give it a new value, so no point nulling it. ... rather than nulling the pointer because you're freeing it ...
    (comp.lang.c)
  • Re: double free
    ... >Does anyone know of a good website that actually describes and ... implementation dependent. ... Obviously the proper way to handle freeing a pointer more than once is ...
    (comp.lang.c)
  • Re: free()
    ... thing, but also because it's actively obfuscating serious problems, ... If a pointer is null, you can free it as often as you like. ... freeing an invalid pointer has undefined and indeterminate results. ...
    (comp.lang.c)
  • Re: Why it is not good code for constructor
    ... How can C's destructor free the memory? ... responsible for freeing it, but C::~C will not be called, and a function-try ... handler cannot access the pointer, while a catch handler in local scope will ... now if new intcompletes ok, but the constructor for A throws, the ...
    (microsoft.public.vc.language)