diff --git a/include/haproxy/action.h b/include/haproxy/action.h index 9ea5847c9..5d751ac42 100644 --- a/include/haproxy/action.h +++ b/include/haproxy/action.h @@ -111,6 +111,7 @@ static inline void release_timeout_action(struct act_rule *rule) release_sample_expr(rule->arg.timeout.expr); } +struct act_rule *new_act_rule(enum act_from from, const char *file, int linenum); void free_act_rules(struct list *rules); #endif /* _HAPROXY_ACTION_H */ diff --git a/src/action.c b/src/action.c index 1644e0b77..a363dea80 100644 --- a/src/action.c +++ b/src/action.c @@ -285,6 +285,21 @@ const char *action_suggest(const char *word, const struct list *keywords, const return best_ptr; } +/* allocates a rule for ruleset (ACT_F_*), from file name and + * line . and may be zero if unknown. Returns the + * rule, otherwise NULL in case of memory allocation error. + */ +struct act_rule *new_act_rule(enum act_from from, const char *file, int linenum) +{ + struct act_rule *rule; + + rule = calloc(1, sizeof(*rule)); + if (!rule) + return NULL; + rule->from = from; + return rule; +} + void free_act_rules(struct list *rules) { struct act_rule *rule, *ruleb; diff --git a/src/http_rules.c b/src/http_rules.c index 4182958a6..bcff27bde 100644 --- a/src/http_rules.c +++ b/src/http_rules.c @@ -81,12 +81,11 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li const struct action_kw *custom = NULL; int cur_arg; - rule = calloc(1, sizeof(*rule)); + rule = new_act_rule(ACT_F_HTTP_REQ, file, linenum); if (!rule) { ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); goto out_err; } - rule->from = ACT_F_HTTP_REQ; if (((custom = action_http_req_custom(args[0])) != NULL)) { char *errmsg = NULL; @@ -160,12 +159,11 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li const struct action_kw *custom = NULL; int cur_arg; - rule = calloc(1, sizeof(*rule)); + rule = new_act_rule(ACT_F_HTTP_RES, file, linenum); if (!rule) { ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); goto out_err; } - rule->from = ACT_F_HTTP_RES; if (((custom = action_http_res_custom(args[0])) != NULL)) { char *errmsg = NULL; @@ -240,12 +238,11 @@ struct act_rule *parse_http_after_res_cond(const char **args, const char *file, const struct action_kw *custom = NULL; int cur_arg; - rule = calloc(1, sizeof(*rule)); + rule = new_act_rule(ACT_F_HTTP_RES, file, linenum); if (!rule) { ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); goto out_err; } - rule->from = ACT_F_HTTP_RES; if (((custom = action_http_after_res_custom(args[0])) != NULL)) { char *errmsg = NULL; diff --git a/src/tcp_rules.c b/src/tcp_rules.c index 9af3005c4..375da6bef 100644 --- a/src/tcp_rules.c +++ b/src/tcp_rules.c @@ -1060,7 +1060,7 @@ static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx, return 0; } - rule = calloc(1, sizeof(*rule)); + rule = new_act_rule(ACT_F_TCP_RES_CNT, file, line); if (!rule) { memprintf(err, "parsing [%s:%d] : out of memory", file, line); return -1; @@ -1076,7 +1076,6 @@ static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx, where |= SMP_VAL_FE_RES_CNT; if (curpx->cap & PR_CAP_BE) where |= SMP_VAL_BE_RES_CNT; - rule->from = ACT_F_TCP_RES_CNT; if (tcp_parse_response_rule(args, arg, section_type, curpx, defpx, rule, err, where, file, line) < 0) goto error; @@ -1178,7 +1177,7 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx, return 0; } - rule = calloc(1, sizeof(*rule)); + rule = new_act_rule(0, file, line); if (!rule) { memprintf(err, "parsing [%s:%d] : out of memory", file, line); return -1; diff --git a/src/tcpcheck.c b/src/tcpcheck.c index 6109f5afe..aa6db673a 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -2336,13 +2336,12 @@ struct tcpcheck_rule *parse_tcpcheck_action(char **args, int cur_arg, struct pro struct tcpcheck_rule *chk = NULL; struct act_rule *actrule = NULL; - actrule = calloc(1, sizeof(*actrule)); + actrule = new_act_rule(ACT_F_TCP_CHK, file, line); if (!actrule) { memprintf(errmsg, "out of memory"); goto error; } actrule->kw = kw; - actrule->from = ACT_F_TCP_CHK; cur_arg++; if (kw->parse((const char **)args, &cur_arg, px, actrule, errmsg) == ACT_RET_PRS_ERR) {