DtY @ Thu May 21, 2009 8:38 am wrote:
char * greeting(const char * name)
char * output = (char *)malloc(sizeof(char) * (9 + strlen(name)));
sprintf(output, "Hello, %s!", name);
Wouldn't the line with malloc(); lead to a memory leak? You're not freeing it.
Why in the world would I free that memory within the function itself?
The whole point of allocating on the heap is so that the function returns a valid pointer.