From: Christopher Faulet Date: Tue, 12 May 2020 16:57:28 +0000 (+0200) Subject: MINOR: http-htx: Use a dedicated function to release http_reply objects X-Git-Tag: v2.2-dev8~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18630643a9b8de6f1b7392cb4ea7849bf67ccb78;p=thirdparty%2Fhaproxy.git MINOR: http-htx: Use a dedicated function to release http_reply objects A function to release an http_reply object has been added. It is now called when an http return rule is released. --- diff --git a/include/proto/http_htx.h b/include/proto/http_htx.h index 9a70ca52db..2307838e59 100644 --- a/include/proto/http_htx.h +++ b/include/proto/http_htx.h @@ -60,6 +60,8 @@ unsigned int http_get_htx_fhdr(const struct htx *htx, const struct ist hdr, int occ, struct http_hdr_ctx *ctx, char **vptr, size_t *vlen); int http_str_to_htx(struct buffer *buf, struct ist raw); +void release_http_reply(struct http_reply *http_reply); + struct buffer *http_load_errorfile(const char *file, char **errmsg); struct buffer *http_load_errormsg(const char *key, const struct ist msg, char **errmsg); struct buffer *http_parse_errorfile(int status, const char *file, char **errmsg); diff --git a/src/http_act.c b/src/http_act.c index 09bed9229e..04c27eaee6 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -1804,44 +1804,10 @@ static enum act_parse_ret parse_http_strict_mode(const char **args, int *orig_ar return ACT_RET_PRS_OK; } -/* Release <.arg.http_return> */ +/* Release <.arg.http_reply> */ static void release_http_return(struct act_rule *rule) { - struct logformat_node *lf, *lfb; - struct http_reply_hdr *hdr, *hdrb; - - if (!rule->arg.http_reply) - return; - - free(rule->arg.http_reply->ctype); - rule->arg.http_reply->ctype = NULL; - list_for_each_entry_safe(hdr, hdrb, &rule->arg.http_reply->hdrs, list) { - LIST_DEL(&hdr->list); - list_for_each_entry_safe(lf, lfb, &hdr->value, list) { - LIST_DEL(&lf->list); - release_sample_expr(lf->expr); - free(lf->arg); - free(lf); - } - istfree(&hdr->name); - free(hdr); - } - - if (rule->arg.http_reply->type == HTTP_REPLY_ERRFILES) { - free(rule->arg.http_reply->body.http_errors); - rule->arg.http_reply->body.http_errors = NULL; - } - else if (rule->arg.http_reply->type == HTTP_REPLY_RAW) - chunk_destroy(&rule->arg.http_reply->body.obj); - else if (rule->arg.http_reply->type == HTTP_REPLY_LOGFMT) { - list_for_each_entry_safe(lf, lfb, &rule->arg.http_reply->body.fmt, list) { - LIST_DEL(&lf->list); - release_sample_expr(lf->expr); - free(lf->arg); - free(lf); - } - } - + release_http_reply(rule->arg.http_reply); rule->arg.http_reply = NULL; } @@ -2387,8 +2353,7 @@ static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, st free(obj); if (fd >= 0) close(fd); - rule->arg.http_reply = reply; /* Set reply to release it */ - release_http_return(rule); + release_http_reply(reply); return ACT_RET_PRS_ERR; } diff --git a/src/http_htx.c b/src/http_htx.c index 2ec300411b..4e8ca0b960 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -954,6 +954,44 @@ error: return 0; } +void release_http_reply(struct http_reply *http_reply) +{ + struct logformat_node *lf, *lfb; + struct http_reply_hdr *hdr, *hdrb; + + if (!http_reply) + return; + + free(http_reply->ctype); + http_reply->ctype = NULL; + list_for_each_entry_safe(hdr, hdrb, &http_reply->hdrs, list) { + LIST_DEL(&hdr->list); + list_for_each_entry_safe(lf, lfb, &hdr->value, list) { + LIST_DEL(&lf->list); + release_sample_expr(lf->expr); + free(lf->arg); + free(lf); + } + istfree(&hdr->name); + free(hdr); + } + + if (http_reply->type == HTTP_REPLY_ERRFILES) { + free(http_reply->body.http_errors); + http_reply->body.http_errors = NULL; + } + else if (http_reply->type == HTTP_REPLY_RAW) + chunk_destroy(&http_reply->body.obj); + else if (http_reply->type == HTTP_REPLY_LOGFMT) { + list_for_each_entry_safe(lf, lfb, &http_reply->body.fmt, list) { + LIST_DEL(&lf->list); + release_sample_expr(lf->expr); + free(lf->arg); + free(lf); + } + } +} + static int http_htx_init(void) { struct buffer chk;