Module: kamailio
Branch: master
Commit: 8be0f000f74cf08e0be6bc7d0a72cae948483416
URL: 
https://github.com/kamailio/kamailio/commit/8be0f000f74cf08e0be6bc7d0a72cae948483416

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2017-08-07T13:39:38+02:00

tm: cleaner handling of dynamic regex param for t_check_status()

---

Modified: src/modules/tm/tm.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/8be0f000f74cf08e0be6bc7d0a72cae948483416.diff
Patch: 
https://github.com/kamailio/kamailio/commit/8be0f000f74cf08e0be6bc7d0a72cae948483416.patch

---

diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c
index 5adef0f02f..68071c3fe4 100644
--- a/src/modules/tm/tm.c
+++ b/src/modules/tm/tm.c
@@ -862,6 +862,7 @@ static int t_check_status(struct sip_msg* msg, char *p1, 
char *foo)
        char backup;
        int lowest_status, n, ret;
        fparam_t* fp;
+       regex_t* re0 = NULL;
        regex_t* re = NULL;
        str tmp;
 
@@ -892,17 +893,18 @@ static int t_check_status(struct sip_msg* msg, char *p1, 
char *foo)
                        memcpy(s, tmp.s, tmp.len);
                        s[tmp.len] = '\0';
 
-                       if ((re = pkg_malloc(sizeof(regex_t))) == 0) {
+                       if ((re0 = pkg_malloc(sizeof(regex_t))) == 0) {
                                LM_ERR("No memory left\n");
                                goto error;
                        }
 
-                       if (regcomp(re, s, REG_EXTENDED|REG_ICASE|REG_NEWLINE)) 
{
+                       if (regcomp(re0, s, 
REG_EXTENDED|REG_ICASE|REG_NEWLINE)) {
                                LM_ERR("Bad regular expression '%s'\n", s);
-                               pkg_free(re);
-                               re = NULL;
+                               pkg_free(re0);
+                               re0 = NULL;
                                goto error;
                        }
+                       re = re0;
                        break;
        }
 
@@ -953,9 +955,9 @@ static int t_check_status(struct sip_msg* msg, char *p1, 
char *foo)
 
        if (backup) status[msg->first_line.u.reply.status.len] = backup;
        if (s) pkg_free(s);
-       if (fp->type != FPARAM_REGEX) {
-               regfree(re);
-               pkg_free(re);
+       if (re0) {
+               regfree(re0);
+               pkg_free(re0);
        }
 
        if (unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))){
@@ -975,9 +977,9 @@ static int t_check_status(struct sip_msg* msg, char *p1, 
char *foo)
                set_t(T_UNDEFINED, T_BR_UNDEFINED);
        }
        if (s) pkg_free(s);
-       if ((fp->type != FPARAM_REGEX) && re) {
-               regfree(re);
-               pkg_free(re);
+       if (re0) {
+               regfree(re0);
+               pkg_free(re0);
        }
        return -1;
 }


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to