]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-htx: Use a dedicated function to release http_reply objects
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 May 2020 16:57:28 +0000 (18:57 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 20 May 2020 16:27:13 +0000 (18:27 +0200)
A function to release an http_reply object has been added. It is now called when
an http return rule is released.

include/proto/http_htx.h
src/http_act.c
src/http_htx.c

index 9a70ca52db42c4302f6f6c4e14f0d9d26035acd9..2307838e5912524a094dd30d935ecdd842274cc2 100644 (file)
@@ -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);
index 09bed9229e3890eef378de967917a9eb598d304b..04c27eaee684dada3027916109a609d4af357c50 100644 (file)
@@ -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;
 }
 
index 2ec300411beaac1b94afcefc14b77be2544c0d14..4e8ca0b9604852ed55a9502c3db8660130ae852c 100644 (file)
@@ -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;