I have a function, foo(), that allocates memory and returns it. Is it standard practice for me to free it at the end of my main function?
char* foo(){
char * p;
p = malloc(sizeof(char) * 4); /* edit - thanks to msg board */
p[0] = 'a';
p[1] = 'b';
p[2] = 'c';
p[3] = '/0'; /* edit: thanks to the msg board. */
return p;
}
int main(int argc, char *argv[])
{
char * p2;
p2 = foo();
printf("%s", p2);
free(p2);
return 0;
}