Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top