문제

I'm coding for pebble and it doesn't allow to use free()

I want to get current time and this works. But I'm not sure if it's memory safe. I mean ts - is a pointer and I think it will need to be free() after use

struct tm *ts;
  time_t timestamp = time(NULL);
  ts = localtime(&timestamp);

Will it be memory leak here? If yes, how to change the code so it will not be any leaks?

도움이 되었습니까?

해결책

No, there is no leak.

The function returns a pointer to an internal object, which hold the correct data untul the next call to localtime().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top