tmrec: use localtime_r() for a safer multi-thread usage
authorVictor Seva <linuxmaniac@torreviejawireless.org>
Tue, 12 May 2020 14:27:58 +0000 (16:27 +0200)
committerVictor Seva <linuxmaniac@torreviejawireless.org>
Tue, 12 May 2020 14:27:58 +0000 (16:27 +0200)
src/modules/tmrec/tmrec_mod.c

index 4bf21f9..cc97cc9 100644 (file)
@@ -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;