|
From: Verdi M. <ver...@co...> - 2006-06-19 17:15:35
|
Hi,
On Tuesday 20 June 2006 00:38, Tom Hughes wrote:
> > /***********************************/
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> > int main() {
> > int *ip;
> > ip =(int *) malloc(sizeof(int));
> > return 0;
> > }
> > /***********************************/
>
> The only pointer to that memory is "ip" and once you return from
> main that variables goes out of scope and you no longer have any
> valid pointers to the memory.
I see. But when main() returns, the program will terminate and the
memory being used will be released anyway. The reason I was hoping
this being a case of "reachable" is that often I don't explicitly
free() pointers which will be used until a program terminates.
Just for curiosity, I changed the program to "exit(0)" instead
of "return 0", and valgrind now reports "unreachable" instead
of "definite lost". Does it mean that I should always use "exit"
to terminate programs? I thought that in main(), both "return" and
"exit" achieve the same effect.
--
Regards,
Verdi
|