my function:
struct hostent * gethost(char * hostname){
if(/*some condition under which I want
to change the mode of my program to not take a host*/){
return null
}
else{
struct hostent * host = gethostbyname(hostname);
return host;
}
}
in main:
struct hostent * host = gethost(argv[2]);
(ignore any minor errors in the code, I'm spewing from memory)
this works fine. and Valgrind doesn't tell me I'm losing memory, despite the fact I'm not freeing.
Why? I thought stuff allocated on the stack disappears with the function call returning? or is it because I return the pointer? is this dangerous in any way?