Re: writing to freed memory--issues



In article <1143486280.691193.21870@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
bill pursell <bill.pursell@xxxxxxxxx> wrote:

I was playing around with a toy program, which led to some confusion.
I had expected that doing the following would lead to an immediate
segfault:
free(a);
*a=0;

You are returning the memory to the C run time library. That doesn't
mean your process loses access. The free() function usually just
returns the memory to a pool to be used in later calls to malloc().

See this for more info:

http://lists.linuxcoding.com/libc/Freeing-after-Malloc.html

--
http://www.spinics.net/lists/linux-c-programming/
http://www.spinics.net/lists/linux-newbi/

.



Relevant Pages

  • Re: Errno 25 ENOTTY then SIGSEGV, socket on accept call? Help.
    ... the problem (you might even find the cause of the segfault yourself ... Your compiler should tell you so. ... you probably didn't allocate enough memory ... If it isn't 'hostname' isn't some- ...
    (comp.unix.programmer)
  • Linux 2.6.8 SegFaulting...
    ... CPUs, 3GB of memory, a pair of 146GB disks on the SmartArray 5i ... contoller, a QL2314 Fibrechannel card, and is using abou 60GB on an HP ... Segfault info, and it was saying something about swapper. ...
    (Linux-Kernel)
  • Re: seg fault on kse_release () (fwd)
    ... Yan is actually correct. ... He's is casting the int to a pointer ... and shouldn't cause a segfault. ... You should also be aware that FreeBSD can overcommit memory. ...
    (freebsd-hackers)
  • Re: [opensuse] sendmail segfaults
    ... to segfault everytime on the same address since last year: ... Was the memory the problem? ... I cant' do offline memory tests actually. ...
    (SuSE)
  • Re: This program makes Python segfault - no other does
    ... The segfault happens at freeing the memory (as the ... That or some other bug corrupts memory structures, ... you should assume that malloc and fre aren't bugged at ... Example code that will likely segfault in free or at the program exit/next ...
    (comp.lang.python)