Browse code

libs/srdb1: use thread safe localtime_r()

Daniel-Constantin Mierla authored on 04/05/2020 16:26:47
Showing 1 changed files
... ...
@@ -350,7 +350,7 @@ int db_str2time(const char* _s, time_t* _v)
350 350
  */
351 351
 int db_time2str_ex(time_t _v, char* _s, int* _l, int _qmode)
352 352
 {
353
-	struct tm* t;
353
+	struct tm t;
354 354
 	int l;
355 355
 
356 356
 	if ((!_s) || (!_l) || (*_l < 2)) {
... ...
@@ -361,8 +361,8 @@ int db_time2str_ex(time_t _v, char* _s, int* _l, int _qmode)
361 361
 	if(_qmode) *_s++ = '\'';
362 362
 
363 363
 	/* Convert time_t structure to format accepted by the database */
364
-	t = localtime(&_v);
365
-	l = strftime(_s, *_l -1, "%Y-%m-%d %H:%M:%S", t);
364
+	localtime_r(&_v, &t);
365
+	l = strftime(_s, *_l -1, "%Y-%m-%d %H:%M:%S", &t);
366 366
 
367 367
 	if (l == 0) {
368 368
 		LM_ERR("Error during time conversion\n");