free memory when it is no longer in use
in function fm_db_util_get_timestamp() 172: char *tstr = strdup(str); memory obtained from strdup() is done dynamically using malloc(). it should be freed when tstr is no longer in use. test case: 1. one controller + one compute deploy (virtual) success to deploy and create an instance. Closes-Bug: 1794705 Change-Id: I0d0c1e6e4386128d6cb38741d80af22a5f10b770
This commit is contained in:
parent
2185575e38
commit
5dd702e05f
@ -160,20 +160,21 @@ bool fm_db_util_get_timestamp(const char *str, FMTimeT &ft){
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
memset(&ts, 0, sizeof(ts));
|
memset(&ts, 0, sizeof(ts));
|
||||||
// only check if the year is present
|
// only check if the year is present
|
||||||
if (strlen(str) < 10){
|
if (strlen(str) < 10) {
|
||||||
//get the current time
|
//get the current time
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
}else{
|
}else {
|
||||||
struct tm t;
|
struct tm t;
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
strptime(str, "%F %T", &t);
|
strptime(str, "%F %T", &t);
|
||||||
ts.tv_sec = mktime(&t);
|
ts.tv_sec = mktime(&t);
|
||||||
//now get the nanoseconds
|
//now get the nanoseconds
|
||||||
char *tstr = strdup(str);
|
char *tstr = strdup(str);
|
||||||
strsep(&tstr, ".");
|
char *tobe_free = strsep(&tstr, ".");
|
||||||
if (tstr != NULL){
|
if (tstr != NULL) {
|
||||||
ts.tv_nsec = atol(tstr)*1000;
|
ts.tv_nsec = atol(tstr)*1000;
|
||||||
}
|
}
|
||||||
|
free(tobe_free);
|
||||||
}
|
}
|
||||||
ft = ts.tv_sec*1000000 + ts.tv_nsec/1000;
|
ft = ts.tv_sec*1000000 + ts.tv_nsec/1000;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user