Re: Malloc/Free - freeing memory allocated by malloc

From: Felipe Magno de Almeida (felipe.almeida_at_ic.unicamp.br)
Date: 09/22/04


Date: Wed, 22 Sep 2004 12:30:46 -0300

Dan Pop wrote:

> In <c48d0aae.0409210021.2712d1c1@posting.google.com> p19010101@yahoo.com (Peter) writes:
>
>
>>Thanks everyone for replying, I will definitely "free" after each
>>"malloc". Something strange is that after calls to "free", the linked
>>list is still accessible, the values are still there.
>
>
> If you can still access those addresses, it means that the freed memory
> still belongs to your program (it is available for further allocation).
> The free() function typically doesn't touch the contents of the memory it
> deallocates.
>
> However, there are implementations where, under certain conditions, the
> deallocated memory no longer belongs to the program. Trying to access
> the freed memory will crash your program.
>
>
>>Should I also assign NULL value to each node?
>
>
> What for? If you're concerned about security issues (you don't want your
> data to be available to whatever program might "inherit" the memory you
> have freed), don't worry: the operating system is supposed to clear the
> memory before allocating it to another program.
>
> Dan
I think it is not necessarily true, not all operating systems clear the
memory before allocating it to another program. Probably if he is really
concerned about security issues on his data that is freed he should
clear it before freeing, and even ask the SO to not let it go to its
swap space.

-- 
    Felipe Magno de Almeida
    UIN: 2113442
     email: felipe.almeida@ic unicamp br, felipe.m.almeida@gmail com
I am a C, modern C++, MFC, ODBC, Windows Services, MAPI developer
from synergy, and Computer Science student from State
University of Campinas(UNICAMP).
To know more about:
Unicamp: http://www.ic.unicamp.br
Synergy: http://www.synergy.com.br
current work: http://www.mintercept.com


Relevant Pages

  • Re: Malloc/Free - freeing memory allocated by malloc
    ... If you're concerned about security issues (you don't want your ... >> memory before allocating it to another program. ... Dan Pop ...
    (comp.lang.c)
  • Re: Garbage Collection
    ... Garbage collection is when freed memory is marked as unused but remains ... and you can always use pointer and manual allocating... ...
    (borland.public.delphi.non-technical)
  • Re: How to release heap memory that is marked as free
    ... Code and using managed objects will you see any form of garbage collection. ... The memory is *not* part of the working ... This is what the Virtual Memory Manager does, and there's no reason you need to do ... The freed memory becomes part of my process's 'working set'. ...
    (microsoft.public.vc.mfc)
  • Re: How to release heap memory that is marked as free
    ... Are you sure this is really what you want to do (swap your whole program ... Calling this function is suppose to clear all freed memory from the ... to do with causing the process to flush the heap somehow and I believe ...
    (microsoft.public.vc.mfc)
  • Re: How to release heap memory that is marked as free
    ... Actually the memory does still belong to the process, ... Apparently Windows does not reclaim the freed memory from the heap until it ... The freed memory becomes part of my process's 'working set'. ... I remember that there is a way to force Windows to reclaim the freed memory, ...
    (microsoft.public.vc.mfc)