[sr-dev] git:master:92e2c22c: tmrec: use localtime_r() for a safer multi-thread usage

Victor Seva linuxmaniac at torreviejawireless.org
Tue May 12 16:28:47 CEST 2020


Module: kamailio
Branch: master
Commit: 92e2c22c3c709c3c9a5243b5d5bdd48293865b0c
URL: https://github.com/kamailio/kamailio/commit/92e2c22c3c709c3c9a5243b5d5bdd48293865b0c

Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date: 2020-05-12T16:27:58+02:00

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

---

Modified: src/modules/tmrec/tmrec_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/92e2c22c3c709c3c9a5243b5d5bdd48293865b0c.diff
Patch: https://github.com/kamailio/kamailio/commit/92e2c22c3c709c3c9a5243b5d5bdd48293865b0c.patch

---

diff --git a/src/modules/tmrec/tmrec_mod.c b/src/modules/tmrec/tmrec_mod.c
index 4bf21f9bad..cc97cc9b55 100644
--- a/src/modules/tmrec/tmrec_mod.c
+++ b/src/modules/tmrec/tmrec_mod.c
@@ -128,9 +128,9 @@ static void mod_destroy(void)
 static int w_is_leap_year(struct sip_msg* msg, char* t, char* str2)
 {
 	time_t tv;
-	struct tm *tb;
+	struct tm tb;
 	int y;
-	
+
 	if(msg==NULL)
 		return -1;
 
@@ -143,8 +143,8 @@ static int w_is_leap_year(struct sip_msg* msg, char* t, char* str2)
 		}
 	} else {
 		tv = time(NULL);
-		tb = localtime(&tv);
-		y = 1900 + tb->tm_year;
+		localtime_r(&tv, &tb);
+		y = 1900 + tb.tm_year;
 	}
 
 	if(tr_is_leap_year(y))
@@ -155,12 +155,12 @@ static int w_is_leap_year(struct sip_msg* msg, char* t, char* str2)
 static int ki_is_leap_year_now(sip_msg_t* msg)
 {
 	time_t tv;
-	struct tm *tb;
+	struct tm tb;
 	int y;
 
 	tv = time(NULL);
-	tb = localtime(&tv);
-	y = 1900 + tb->tm_year;
+	localtime_r(&tv, &tb);
+	y = 1900 + tb.tm_year;
 
 	if(tr_is_leap_year(y))
 		return 1;




More information about the sr-dev mailing list