abcd12344445555
Programmer
In the following class I'm using the C lib <time.h> .
The functions gmtime, ctime, and asctime return pointers to char/structs.
Am I responsible to clean the memory allocated by them? Is there any possible memory leak associated to the methods MyTimeClass::getDateAndTimeLocalTime() and MyTimeClass::getDateAndTimeUTC() described bellow?
Thanks;
The functions gmtime, ctime, and asctime return pointers to char/structs.
Am I responsible to clean the memory allocated by them? Is there any possible memory leak associated to the methods MyTimeClass::getDateAndTimeLocalTime() and MyTimeClass::getDateAndTimeUTC() described bellow?
Code:
Class MyTimeClass{
public:
string getDateAndTimeLocalTime();
string getDateAndTimeUTC();
...
private:
time_t dateAndTime;
};
string MyTimeClass::getDateAndTimeLocalTime() {
string result;
result.append(ctime(&this->dateAndTime));
return result;
}
string MyTimeClass::getDateAndTimeUTC() {
string result;
result.append(asctime(gmtime(&this->dateAndTime)));
return result;
}
Thanks;