It's been a while since I've used C, and I think I've coded myself into a corner.
(I could quite easily change the way I'm doing things to avoid this problem but it's now become academic matter for me
)
I have a function which should return the date.
Note the commented out line. This function works if I uncomment it but then I run into the problem of how to free memory after the function has returned!
What is the usual way to go about this? And by this I mean freeing memory but only after a function has returned?
inb4 Pass a pointer as an argument and write to that...
(I could quite easily change the way I'm doing things to avoid this problem but it's now become academic matter for me

I have a function which should return the date.
Code:
/** Get current date and time. */
char *
get_time(void)
{
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
char buffer[MAX_TIME_STRING];
//char * buffer = malloc(MAX_TIME_STRING);
strftime(buffer, MAX_TIME_STRING, "%c", timeinfo);
return buffer;
}
Note the commented out line. This function works if I uncomment it but then I run into the problem of how to free memory after the function has returned!
What is the usual way to go about this? And by this I mean freeing memory but only after a function has returned?
inb4 Pass a pointer as an argument and write to that...