Frage

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?

War es hilfreich?

Lösung

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().

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top