I have this code:
int tim=10000; // some random number
tm *now=localtime(&tim);
printf("Date is %d/%02d/%02d\n", now->tm_year+1900, now->tm_mon+1, now->tm_mday);
printf("Time is %02d:%02d\n", now->tm_hour, now->tm_min);
我在想这段代码是否存在内存泄漏的原因是 localtime 返回一个指向结构体的指针,这意味着它会分配内存,但是没有人释放它。
这段代码是否存在内存泄漏?
localtime
中发生了什么吗? - Cory Kramertime_t
而不是整数。 - Marco A.int
,但这并不保证,因此最好使用标准化类型。 - Jens Gustedtstruct tm * localtime_r(time_t * tim, struct tm * output)
。 - Wolf