pv: use localtime_r() for a safer multi-thread usage
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 6 May 2020 15:03:45 +0000 (17:03 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 6 May 2020 15:03:45 +0000 (17:03 +0200)
src/modules/pv/pv_trans.c

index 826fa9c..d07e55e 100644 (file)
@@ -195,6 +195,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
        pv_value_t v, w;
        time_t t;
        uint32_t sz1, sz2;
+       struct tm tmv;
 
        if(val==NULL || val->flags&PV_VAL_NULL)
                return -1;
@@ -1045,8 +1046,8 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
                        memcpy(s, st.s, st.len);
                        s[st.len] = '\0';
                        t = val->ri;
-                       val->rs.len = strftime(_tr_buffer, TR_BUFFER_SIZE-1, s,
-                                       localtime(&t));
+                       localtime_r(&t, &tmv);
+                       val->rs.len = strftime(_tr_buffer, TR_BUFFER_SIZE-1, s, &tmv);
                        pkg_free(s);
                        val->flags = PV_VAL_STR;
                        val->rs.s = _tr_buffer;