Re: Malloc/Free - freeing memory allocated by malloc
From: Felipe Magno de Almeida (felipe.almeida_at_ic.unicamp.br)
Date: 09/22/04
- Next message: Randy Howard: "Re: Newbie-question: scanf alternatives?"
- Previous message: Felipe Magno de Almeida: "Re: Newbie-question: scanf alternatives?"
- In reply to: Dan Pop: "Re: Malloc/Free - freeing memory allocated by malloc"
- Next in thread: Dan Pop: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Dan Pop: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Michael Wojcik: "Re: Malloc/Free - freeing memory allocated by malloc"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Randy Howard: "Re: Newbie-question: scanf alternatives?"
- Previous message: Felipe Magno de Almeida: "Re: Newbie-question: scanf alternatives?"
- In reply to: Dan Pop: "Re: Malloc/Free - freeing memory allocated by malloc"
- Next in thread: Dan Pop: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Dan Pop: "Re: Malloc/Free - freeing memory allocated by malloc"
- Reply: Michael Wojcik: "Re: Malloc/Free - freeing memory allocated by malloc"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|