]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: regex: The pointer regstr in the struc regex is no longer used.
authorThierry FOURNIER <tfournier@exceliance.fr>
Wed, 29 Jan 2014 18:35:16 +0000 (19:35 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 17 Mar 2014 17:06:08 +0000 (18:06 +0100)
The pointer <regstr> is only used to compare and identify the original
regex string with the patterns. Now the patterns have a reference map
containing this original string. It is useless to store this value two
times.

include/common/regex.h
src/pattern.c
src/regex.c

index a3d1b5f400513d71d5fd9b5a988fbbf77f0f0f49..9789ec3c9bea2eaa70c88b67e333f06eaf0a1bc1 100644 (file)
@@ -47,7 +47,6 @@ struct my_regex {
 #else /* no PCRE */
        regex_t regex;
 #endif
-       char *regstr; /* this contain the original string */
 };
 
 /* what to do when a header matches a regex */
@@ -109,8 +108,6 @@ static inline void regex_free(struct my_regex *preg) {
 #else
        regfree(&preg->regex);
 #endif
-       free(preg->regstr);
-       preg->regstr = NULL;
 }
 
 #endif /* _COMMON_REGEX_H */
index 43d6e968e64eb6d5a9dfd687a2aa7019cf984c6a..94b338c3b4f184b3f21344d75c828dfbaa556671 100644 (file)
@@ -231,8 +231,7 @@ int pat_parse_reg(const char *text, struct pattern *pattern, char **err)
                return 0;
        }
 
-       pattern->ptr.reg = (struct my_regex *)trash->str;
-       pattern->ptr.reg->regstr = (char *)text;
+       pattern->ptr.str = (char *)text;
 
        return 1;
 }
@@ -1037,7 +1036,7 @@ int pat_idx_list_reg(struct pattern_expr *expr, struct pattern *pat, char **err)
        }
 
        /* compile regex */
-       if (!regex_comp(pat->ptr.reg->regstr, patl->pat.ptr.reg, !(patl->pat.flags & PAT_F_IGNORE_CASE), 0, err)) {
+       if (!regex_comp(pat->ptr.str, patl->pat.ptr.reg, !(patl->pat.flags & PAT_F_IGNORE_CASE), 0, err)) {
                free(patl);
                free(patl->pat.ptr.reg);
                return 0;
index 64f93c30ecdf7b11382dc92d9462e94507383da2..7a7694050b41cd666f06c76bad1f3b89dc589ee9 100644 (file)
@@ -124,13 +124,6 @@ const char *chain_regex(struct hdr_exp **head, const regex_t *preg,
 
 int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **err)
 {
-       /* copy the original regex format */
-       regex->regstr = strdup(str);
-       if (!regex->regstr) {
-               memprintf(err, "out of memory");
-               return 0;
-       }
-
 #ifdef USE_PCRE_JIT
        int flags = 0;
        const char *error;
@@ -143,14 +136,12 @@ int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **
 
        regex->reg = pcre_compile(str, flags, &error, &erroffset, NULL);
        if (!regex->reg) {
-               free(regex->regstr);
                memprintf(err, "regex '%s' is invalid (error=%s, erroffset=%d)", str, error, erroffset);
                return 0;
        }
 
        regex->extra = pcre_study(regex->reg, PCRE_STUDY_JIT_COMPILE, &error);
        if (!regex->extra) {
-               free(regex->regstr);
                pcre_free(regex->reg);
                memprintf(err, "failed to compile regex '%s' (error=%s)", str, error);
                return 0;
@@ -164,7 +155,6 @@ int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **
                flags |= REG_NOSUB;
 
        if (regcomp(&regex->regex, str, flags) != 0) {
-               free(regex->regstr);
                memprintf(err, "regex '%s' is invalid", str);
                return 0;
        }