]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: get rid of SMP_F_READ_ONLY and SMP_F_MUST_FREE
authorWilly Tarreau <w@1wt.eu>
Mon, 23 Apr 2012 17:25:44 +0000 (19:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 18:57:15 +0000 (20:57 +0200)
These ones were either unused or improperly used. Some integers were marked
read-only, which does not make much sense. Buffers are not read-only, they're
"constant" in that they must be kept intact after any possible change.

include/proto/acl.h
include/types/pattern.h
src/acl.c
src/backend.c
src/frontend.c
src/proto_http.c
src/protocols.c

index e21075fb6bde7a32bea73ef0e2f025e41fb83678..998ac4362093af1b612d2d3007a17cdc5a485150 100644 (file)
@@ -205,10 +205,8 @@ int acl_match_dom(struct sample *smp, struct acl_pattern *pattern);
 /* Check that the IPv4 address in <test> matches the IP/mask in pattern */
 int acl_match_ip(struct sample *smp, struct acl_pattern *pattern);
 
-/* Executes a regex. It needs to change the data. If it is marked READ_ONLY
- * then it will be allocated and duplicated in place so that others may use
- * it later on. Note that this is embarrassing because we always try to avoid
- * allocating memory at run time.
+/* Executes a regex. It temporarily changes the data to add a trailing zero,
+ * and restores the previous character when leaving.
  */
 int acl_match_reg(struct sample *smp, struct acl_pattern *pattern);
 
index 8fcc5d89c390523bea645cf507a9bb5c13ee18b7..c710b207c28c01f31335663059b233728acd4174 100644 (file)
@@ -54,10 +54,6 @@ enum {
        SMP_F_VOL_TXN    = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */
        SMP_F_VOL_SESS   = 1 << 6, /* result sensitive to new session (eg: src IP) */
        SMP_F_VOLATILE   = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
-
-       SMP_F_READ_ONLY  = 1 << 7, /* returned data must not be altered */
-       SMP_F_MUST_FREE  = 1 << 10, /* migration: this sample must be freed ASAP */
-
 };
 
 /* pattern fetch direction */
index 9c4ce0ca53dea9eb7caf26a2e6d7f06ed0a00e93..5d86a3e1a1f49489ad314838417dfe7f1c7f6044 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -623,32 +623,14 @@ static void *acl_lookup_str(struct sample *smp, struct acl_expr *expr)
        return node;
 }
 
-/* Executes a regex. It needs to change the data. If it is marked READ_ONLY
- * then it will be allocated and duplicated in place so that others may use
- * it later on. Note that this is embarrassing because we always try to avoid
- * allocating memory at run time.
+/* Executes a regex. It temporarily changes the data to add a trailing zero,
+ * and restores the previous character when leaving.
  */
 int acl_match_reg(struct sample *smp, struct acl_pattern *pattern)
 {
        char old_char;
        int ret;
 
-       if (unlikely(smp->flags & SMP_F_READ_ONLY)) {
-               char *new_str;
-
-               new_str = calloc(1, smp->data.str.len + 1);
-               if (!new_str)
-                       return ACL_PAT_FAIL;
-
-               memcpy(new_str, smp->data.str.str, smp->data.str.len);
-               new_str[smp->data.str.len] = 0;
-               if (smp->flags & SMP_F_MUST_FREE)
-                       free(smp->data.str.str);
-               smp->data.str.str = new_str;
-               smp->flags |= SMP_F_MUST_FREE;
-               smp->flags &= ~SMP_F_READ_ONLY;
-       }
-
        old_char = smp->data.str.str[smp->data.str.len];
        smp->data.str.str[smp->data.str.len] = 0;
 
@@ -1903,12 +1885,6 @@ int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, v
                                 *
                                 */
 
-                               /* now we may have some cleanup to do */
-                               if (smp.flags & SMP_F_MUST_FREE) {
-                                       free(smp.data.str.str);
-                                       smp.data.str.len = 0;
-                               }
-
                                /* we're ORing these terms, so a single PASS is enough */
                                if (acl_res == ACL_PAT_PASS)
                                        break;
index 4d0d86f14c4cfd1eae3ddc16c8402330b56af5e8..fc8f22fa2dcd3bc4ab0d46da73c9eee69d8e1f28 100644 (file)
@@ -1456,7 +1456,6 @@ static int
 acl_fetch_be_id(struct proxy *px, struct session *l4, void *l7, int dir,
                 struct acl_expr *expr, struct sample *smp)
 {
-       smp->flags = SMP_F_READ_ONLY;
        smp->flags = SMP_F_VOL_TXN;
        smp->type = SMP_T_UINT;
        smp->data.uint = l4->be->uuid;
@@ -1471,7 +1470,6 @@ acl_fetch_srv_id(struct proxy *px, struct session *l4, void *l7, int dir,
        if (!target_srv(&l4->target))
                return 0;
 
-       smp->flags = SMP_F_READ_ONLY;
        smp->type = SMP_T_UINT;
        smp->data.uint = target_srv(&l4->target)->puid;
 
index 2e0237a8e105548387d287ebd18b14889ceba272..c44cd920b8ba1ef6acffb38e4b3e0dba2088bbb7 100644 (file)
@@ -502,7 +502,6 @@ static int
 acl_fetch_fe_id(struct proxy *px, struct session *l4, void *l7, int dir,
                 struct acl_expr *expr, struct sample *smp)
 {
-       smp->flags = SMP_F_READ_ONLY;
        smp->flags = SMP_F_VOL_SESS;
        smp->type = SMP_T_UINT;
        smp->data.uint = l4->fe->uuid;
index b6036d56bbee103636dd2f7794ef57a40e525fb3..f3db6826b9f8dd7c61d9e5f5d343ad32baea8461 100644 (file)
@@ -7665,7 +7665,7 @@ acl_fetch_meth(struct proxy *px, struct session *l4, void *l7, int dir,
                smp->data.str.len = txn->req.sl.rq.m_l;
                smp->data.str.str = txn->req.buf->p + txn->req.sol;
        }
-       smp->flags = SMP_F_READ_ONLY | SMP_F_VOL_1ST;
+       smp->flags = SMP_F_VOL_1ST;
        return 1;
 }
 
@@ -7730,7 +7730,7 @@ acl_fetch_rqver(struct proxy *px, struct session *l4, void *l7, int dir,
        smp->data.str.str = ptr;
        smp->data.str.len = len;
 
-       smp->flags = SMP_F_READ_ONLY | SMP_F_VOL_1ST;
+       smp->flags = SMP_F_VOL_1ST;
        return 1;
 }
 
@@ -7755,7 +7755,7 @@ acl_fetch_stver(struct proxy *px, struct session *l4, void *l7, int dir,
        smp->data.str.str = ptr;
        smp->data.str.len = len;
 
-       smp->flags = SMP_F_READ_ONLY | SMP_F_VOL_1ST;
+       smp->flags = SMP_F_VOL_1ST;
        return 1;
 }
 
@@ -7837,7 +7837,7 @@ acl_fetch_url_port(struct proxy *px, struct session *l4, void *l7, int dir,
        if (px->options & PR_O_HTTP_PROXY)
                l4->flags |= SN_ADDR_SET;
 
-       smp->flags = SMP_F_READ_ONLY;
+       smp->flags = 0;
        return 1;
 }
 
@@ -7965,8 +7965,6 @@ acl_fetch_path(struct proxy *px, struct session *l4, void *l7, int dir,
                ptr++;
 
        smp->data.str.len = ptr - smp->data.str.str;
-
-       /* we do not need to set READ_ONLY because the data is in a buffer */
        smp->flags = SMP_F_VOL_1ST;
        return 1;
 }
index 12d719a90bcc82120827eee5c6f79b05e3db8fd7..52ddbcc93dcfdf38d4346cee7ad9e938de53e419 100644 (file)
@@ -338,7 +338,6 @@ static int
 acl_fetch_so_id(struct proxy *px, struct session *l4, void *l7, int dir,
                 struct acl_expr *expr, struct sample *smp)
 {
-       smp->flags = SMP_F_READ_ONLY;
        smp->type = SMP_T_UINT;
        smp->data.uint = l4->listener->luid;
        return 1;