Browse code

db_redis: use localtime_r() for a safer multi-thread usage

Victor Seva authored on 12/05/2020 12:29:10
Showing 1 changed files
... ...
@@ -81,6 +81,7 @@ static int db_redis_val2str(const db_val_t *v, str *_str) {
81 81
     const char *s;
82 82
     const str *tmpstr;
83 83
     int vtype = VAL_TYPE(v);
84
+    struct tm _time;
84 85
     _str->s = NULL;
85 86
     _str->len = 32; // default for numbers
86 87
 
... ...
@@ -144,7 +145,8 @@ static int db_redis_val2str(const db_val_t *v, str *_str) {
144 145
             LM_DBG("converting datetime value %ld to str\n", VAL_TIME(v));
145 146
             _str->s = (char*)pkg_malloc(_str->len);
146 147
             if (!_str->s) goto memerr;
147
-            strftime(_str->s, _str->len, "%Y-%m-%d %H:%M:%S", localtime(&(VAL_TIME(v))));
148
+            localtime_r(&(VAL_TIME(v)), &_time);
149
+            strftime(_str->s, _str->len, "%Y-%m-%d %H:%M:%S", &_time);
148 150
             _str->len = strlen(_str->s);
149 151
             break;
150 152
         case DB1_DOUBLE: