]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: Use `isttest()` and `istfree()`
authorTim Duesterhus <tim@bastelstu.be>
Thu, 5 Mar 2020 16:56:33 +0000 (17:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 5 Mar 2020 18:52:07 +0000 (19:52 +0100)
This adjusts a few locations to make use of `isttest()` and `istfree()`.

src/fcgi-app.c
src/hlua.c
src/hpack-dec.c
src/http_act.c
src/http_ana.c
src/http_fetch.c
src/http_htx.c
src/mux_h1.c

index 5d26580965b158dc78248f90fdb1099d85099bec..8472cf58dc205bf71d7db86fdb9cec40e0a0325e 100644 (file)
@@ -838,9 +838,9 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw
                }
                if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
                        goto out;
-               free(curapp->docroot.ptr);
+               istfree(&curapp->docroot);
                curapp->docroot = ist2(strdup(args[1]), strlen(args[1]));
-               if (!curapp->docroot.ptr) {
+               if (!isttest(curapp->docroot)) {
                        ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                        err_code |= ERR_ALERT | ERR_ABORT;
                }
@@ -871,9 +871,9 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw
                }
                if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
                        goto out;
-               free(curapp->index.ptr);
+               istfree(&curapp->index);
                curapp->index = ist2(strdup(args[1]), strlen(args[1]));
-               if (!curapp->index.ptr) {
+               if (!isttest(curapp->index)) {
                        ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                        err_code |= ERR_ALERT | ERR_ABORT;
                }
@@ -1070,8 +1070,8 @@ void fcgi_apps_deinit()
                struct fcgi_rule_conf *rule, *back;
 
                free(curapp->name);
-               free(curapp->docroot.ptr);
-               free(curapp->index.ptr);
+               istfree(&curapp->docroot);
+               istfree(&curapp->index);
                regex_free(curapp->pathinfo_re);
                free(curapp->conf.file);
 
index d8e538b637df4fc5f52e2fe596d1f4fa3551d579..4043e29c2d1b584e9a0ba459c1270248e794d141 100644 (file)
@@ -3889,7 +3889,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
        lua_settable(L, -3);
 
        path = http_get_path(htx_sl_req_uri(sl));
-       if (path.ptr) {
+       if (isttest(path)) {
                char *p, *q, *end;
 
                p = path.ptr;
index b4d8f0d393ee2ec4e22343972381b8a06a1c909e..fa25ac47537390bbb02e64a468424f246ed819aa 100644 (file)
@@ -191,7 +191,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len,
                        }
 
                        value = hpack_alloc_string(tmp, idx, hpack_idx_to_value(dht, idx));
-                       if (!value.ptr) {
+                       if (!isttest(value)) {
                                hpack_debug_printf("##ERR@%d##\n", __LINE__);
                                ret = -HPACK_ERR_TOO_LARGE;
                                goto leave;
@@ -202,7 +202,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len,
 
                        if (!name.len) {
                                name = hpack_alloc_string(tmp, idx, hpack_idx_to_name(dht, idx));
-                               if (!name.ptr) {
+                               if (!isttest(name)) {
                                        hpack_debug_printf("##ERR@%d##\n", __LINE__);
                                        ret = -HPACK_ERR_TOO_LARGE;
                                        goto leave;
@@ -412,7 +412,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len,
 
                        if (!name.len) {
                                name = hpack_alloc_string(tmp, idx, hpack_idx_to_name(dht, idx));
-                               if (!name.ptr) {
+                               if (!isttest(name)) {
                                        hpack_debug_printf("##ERR@%d##\n", __LINE__);
                                        ret = -HPACK_ERR_TOO_LARGE;
                                        goto leave;
@@ -444,7 +444,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len,
                }
 
                hpack_debug_printf("\e[1;34m%s\e[0m: ",
-                                  name.ptr ? istpad(trash.area, name).ptr : h2_phdr_to_str(name.len));
+                                  isttest(name) ? istpad(trash.area, name).ptr : h2_phdr_to_str(name.len));
 
                hpack_debug_printf("\e[1;35m%s\e[0m [mustidx=%d, used=%d] [n=(%p,%d) v=(%p,%d)]\n",
                                   istpad(trash.area, value).ptr, must_index,
index 9bfa7ebe44b6d4f582c5232b8e69e8609ad92484..7c16c336c60670716d6c4eb8f9d785f7910f2c02 100644 (file)
@@ -56,8 +56,7 @@ static void release_http_action(struct act_rule *rule)
 {
        struct logformat_node *lf, *lfb;
 
-       if (rule->arg.http.str.ptr)
-               free(rule->arg.http.str.ptr);
+       istfree(&rule->arg.http.str);
        if (rule->arg.http.re)
                regex_free(rule->arg.http.re);
        list_for_each_entry_safe(lf, lfb, &rule->arg.http.fmt, list) {
@@ -1257,7 +1256,7 @@ static enum act_parse_ret parse_http_set_header(const char **args, int *orig_arg
 
        cur_arg++;
        if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) {
-               free(rule->arg.http.str.ptr);
+               istfree(&rule->arg.http.str);
                return ACT_RET_PRS_ERR;
        }
 
@@ -1351,7 +1350,7 @@ static enum act_parse_ret parse_http_replace_header(const char **args, int *orig
 
        cur_arg++;
        if (!(rule->arg.http.re = regex_comp(args[cur_arg], 1, 1, err))) {
-               free(rule->arg.http.str.ptr);
+               istfree(&rule->arg.http.str);
                return ACT_RET_PRS_ERR;
        }
 
@@ -1366,7 +1365,7 @@ static enum act_parse_ret parse_http_replace_header(const char **args, int *orig
 
        cur_arg++;
        if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.fmt, LOG_OPT_HTTP, cap, err)) {
-               free(rule->arg.http.str.ptr);
+               istfree(&rule->arg.http.str);
                regex_free(rule->arg.http.re);
                return ACT_RET_PRS_ERR;
        }
@@ -1829,7 +1828,7 @@ static void release_http_return(struct act_rule *rule)
                                free(lf->arg);
                                free(lf);
                        }
-                       free(hdr->name.ptr);
+                       istfree(&hdr->name);
                        free(hdr);
                }
                free(rule->arg.http_return.hdrs);
@@ -2295,7 +2294,7 @@ static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, st
                                        free(lf->arg);
                                        free(lf);
                                }
-                               free(hdr->name.ptr);
+                               istfree(&hdr->name);
                                free(hdr);
                        }
                }
@@ -2366,7 +2365,7 @@ static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, st
                                        free(lf->arg);
                                        free(lf);
                                }
-                               free(hdr->name.ptr);
+                               istfree(&hdr->name);
                                free(hdr);
                        }
                }
@@ -2444,7 +2443,7 @@ static enum act_parse_ret parse_http_return(const char **args, int *orig_arg, st
                                free(lf->arg);
                                free(lf);
                        }
-                       free(hdr->name.ptr);
+                       istfree(&hdr->name);
                        free(hdr);
                }
                free(hdrs);
index e268d4c951bb86a66032cca8b5c2e214ef231cfc..a97066085fae8f88901414d80d74a1d522b1fe99 100644 (file)
@@ -2503,7 +2503,7 @@ int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struc
                        sl = http_get_stline(htx);
                        path = http_get_path(htx_sl_req_uri(sl));
                        /* build message using path */
-                       if (path.ptr) {
+                       if (isttest(path)) {
                                if (rule->flags & REDIRECT_FLAG_DROP_QS) {
                                        int qs = 0;
                                        while (qs < path.len) {
@@ -2551,7 +2551,7 @@ int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struc
                        sl = http_get_stline(htx);
                        path = http_get_path(htx_sl_req_uri(sl));
                        /* build message using path */
-                       if (path.ptr) {
+                       if (isttest(path)) {
                                if (rule->flags & REDIRECT_FLAG_DROP_QS) {
                                        int qs = 0;
                                        while (qs < path.len) {
@@ -4252,7 +4252,7 @@ void http_perform_server_redirect(struct stream *s, struct stream_interface *si)
        htx = htxbuf(&req->buf);
        sl = http_get_stline(htx);
        path = http_get_path(htx_sl_req_uri(sl));
-       if (!path.ptr)
+       if (!isttest(path))
                return;
 
        if (!chunk_memcat(&trash, path.ptr, path.len))
index dbbb5ecfd2e9884ea83369d10217584ac0e30cc6..9113b5e493fd56d5fb8bafa1a229072b95ccd155 100644 (file)
@@ -987,7 +987,7 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char
 
        sl = http_get_stline(htx);
        path = iststop(http_get_path(htx_sl_req_uri(sl)), '?');
-       if (!path.ptr)
+       if (!isttest(path))
                return 0;
 
        /* OK, we got the '/' ! */
@@ -1028,7 +1028,7 @@ static int smp_fetch_base(const struct arg *args, struct sample *smp, const char
        /* now retrieve the path */
        sl = http_get_stline(htx);
        path = http_get_path(htx_sl_req_uri(sl));
-       if (path.ptr) {
+       if (isttest(path)) {
                size_t len;
 
                for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
@@ -1074,7 +1074,7 @@ static int smp_fetch_base32(const struct arg *args, struct sample *smp, const ch
        /* now retrieve the path */
        sl = http_get_stline(htx);
        path = http_get_path(htx_sl_req_uri(sl));
-       if (path.ptr) {
+       if (isttest(path)) {
                size_t len;
 
                for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
@@ -1422,7 +1422,7 @@ static int smp_fetch_capture_req_uri(const struct arg *args, struct sample *smp,
        path.len = ptr - path.ptr;
 
        path = http_get_path(path);
-       if (!path.ptr)
+       if (!isttest(path))
                return 0;
 
        smp->data.u.str.area = path.ptr;
index 8157eb560b0e9008d787e0bd0f78c8e96e782d45..0e686956c77cfd081becb530725dae664d68eb2e 100644 (file)
@@ -111,7 +111,7 @@ int http_find_header(const struct htx *htx, const struct ist name,
        if (blk) {
                char *p;
 
-               if (!ctx->value.ptr)
+               if (!isttest(ctx->value))
                        goto rescan_hdr;
                if (full)
                        goto next_blk;
@@ -309,7 +309,7 @@ int http_replace_req_path(struct htx *htx, const struct ist path)
 
        uri = htx_sl_req_uri(sl);
        p = http_get_path(uri);
-       if (!p.ptr)
+       if (!isttest(p))
                p = uri;
        while (plen < p.len && *(p.ptr + plen) != '?')
                plen++;
index 2e2dbf943505eb5f0d0b12ccb12f38e5a253acd1..72606293f2d7ad78336bdda8d01d1a07ad986fc8 100644 (file)
@@ -2853,7 +2853,7 @@ static int add_hdr_case_adjust(const char *from, const char *to, char **err)
        entry->name.len = strlen(to);
        if (!entry->node.key || !entry->name.ptr) {
                free(entry->node.key);
-               free(entry->name.ptr);
+               istfree(&entry->name);
                free(entry);
                memprintf(err, "out of memory");
                return -1;
@@ -2873,7 +2873,7 @@ static void h1_hdeaders_case_adjust_deinit()
                ebpt_delete(node);
                entry = container_of(node, struct h1_hdr_entry, node);
                free(entry->node.key);
-               free(entry->name.ptr);
+               istfree(&entry->name);
                free(entry);
                node = next;
        }