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
1 changed files with 6 additions and 5 deletions

View File

@ -170,10 +170,11 @@ bool fm_db_util_get_timestamp(const char *str, FMTimeT &ft){
ts.tv_sec = mktime(&t);
//now get the nanoseconds
char *tstr = strdup(str);
strsep(&tstr, ".");
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;