Browse code

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

Victor Seva authored on 12/05/2020 14:11:29
Showing 1 changed files
... ...
@@ -195,7 +195,7 @@ int acc_log_request( struct sip_msg *rq)
195 195
 	int m;
196 196
 	int o;
197 197
 	int i;
198
-	struct tm *t;
198
+	struct tm t;
199 199
 	double dtime;
200 200
 
201 201
 	/* get default values */
... ...
@@ -262,12 +262,12 @@ int acc_log_request( struct sip_msg *rq)
262 262
 				acc_time_attr.s, dtime, log_msg);
263 263
 	} else if(acc_time_mode==3 || acc_time_mode==4) {
264 264
 		if(acc_time_mode==3) {
265
-			t = localtime(&acc_env.ts);
265
+			localtime_r(&acc_env.ts, &t);
266 266
 		} else {
267
-			t = gmtime(&acc_env.ts);
267
+			gmtime_r(&acc_env.ts, &t);
268 268
 		}
269 269
 		if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
270
-					acc_time_format, t)<=0) {
270
+					acc_time_format, &t)<=0) {
271 271
 			acc_time_format_buf[0] = '\0';
272 272
 		}
273 273
 		LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%s%s",
... ...
@@ -412,7 +412,7 @@ int acc_db_request( struct sip_msg *rq)
412 412
 	int n;
413 413
 	int i;
414 414
 	int o;
415
-	struct tm *t;
415
+	struct tm t;
416 416
 	double dtime;
417 417
 
418 418
 	/* formated database columns */
... ...
@@ -435,12 +435,12 @@ int acc_db_request( struct sip_msg *rq)
435 435
 		i++;
436 436
 	} else if(acc_time_mode==3 || acc_time_mode==4) {
437 437
 		if(acc_time_mode==3) {
438
-			t = localtime(&acc_env.ts);
438
+			localtime_r(&acc_env.ts, &t);
439 439
 		} else {
440
-			t = gmtime(&acc_env.ts);
440
+			gmtime_r(&acc_env.ts, &t);
441 441
 		}
442 442
 		if(strftime(acc_time_format_buf, ACC_TIME_FORMAT_SIZE,
443
-					acc_time_format, t)<=0) {
443
+					acc_time_format, &t)<=0) {
444 444
 			acc_time_format_buf[0] = '\0';
445 445
 		}
446 446
 		VAL_STRING(db_vals+(m++)) = acc_time_format_buf;