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:
SidneyAn 2018-10-29 15:29:21 +08:00 committed by Ran An
parent 2185575e38
commit 5dd702e05f

View File

@ -160,20 +160,21 @@ bool fm_db_util_get_timestamp(const char *str, FMTimeT &ft){
struct timespec ts;
memset(&ts, 0, sizeof(ts));
// only check if the year is present
if (strlen(str) < 10){
if (strlen(str) < 10) {
//get the current time
clock_gettime(CLOCK_REALTIME, &ts);
}else{
}else {
struct tm t;
memset(&t, 0, sizeof(t));
strptime(str, "%F %T", &t);
ts.tv_sec = mktime(&t);
//now get the nanoseconds
char *tstr = strdup(str);
strsep(&tstr, ".");
if (tstr != NULL){
char *tobe_free = strsep(&tstr, ".");
if (tstr != NULL) {
ts.tv_nsec = atol(tstr)*1000;
}
free(tobe_free);
}
ft = ts.tv_sec*1000000 + ts.tv_nsec/1000;
return true;
@ -352,7 +353,7 @@ bool fm_db_util_event_log_build_sql_insert(std::map<std::string,std::string> &ma
param.assign(str);
cmd_params += param;
}
cmd_params.resize(cmd_params.size()-1);
params.db_cmd = "INSERT INTO ";
params.db_cmd += FM_EVENT_LOG_TABLE_NAME;