Should I free up memory returned by the following two functions in the caller function? I see that it is ok with function get_current_time but not ok with the get_filename_ext. I see similar question here, but not sure that answers my question. In general what should I look for?
char *get_current_time(void){
struct tm *local;
time_t t;
t = time(NULL);
local = gmtime(&t);
return asctime(local);
}
char *get_filename_ext(const char *filename) {
const char *dot = strrchr(filename, '.');
if(!dot || dot == filename) return "";
return dot + 1;
}
Neither of these functions allocate any memory. So there’s actually nothing to free.
The
char*returned byasctimeis an internal buffer. So you can’t free it anyway.