]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stream: only free the req/res captures when set
authorWilly Tarreau <w@1wt.eu>
Thu, 23 Jun 2022 09:46:14 +0000 (11:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 23 Jun 2022 09:49:09 +0000 (11:49 +0200)
There's a subtle bug in stream_free() when releasing captures. The
pools may be NULL when no capture is defined, and the calls to
pool_free() are inconditional. The only reason why this doesn't
cause trouble is because the pointer to be freed is always NULL in
this case and we don't go further down the chain. That's particularly
ugly and it complicates debugging, so let's only call these ones when
the pointers are set.

There's no impact on running code, it only fools those trying to debug
pools manually. There's no need to backport it though it unless it helps
for debugging sessions.

src/stream.c

index 5de7cdda71c1c3889345e314a83b04bad0e472d4..7df2cc6076dfc5d44a668344944fa1dd1a8e4e13 100644 (file)
@@ -672,16 +672,15 @@ void stream_free(struct stream *s)
                        struct cap_hdr *h;
                        for (h = fe->req_cap; h; h = h->next)
                                pool_free(h->pool, s->req_cap[h->index]);
+                       pool_free(fe->req_cap_pool, s->req_cap);
                }
 
                if (s->res_cap) {
                        struct cap_hdr *h;
                        for (h = fe->rsp_cap; h; h = h->next)
                                pool_free(h->pool, s->res_cap[h->index]);
+                       pool_free(fe->rsp_cap_pool, s->res_cap);
                }
-
-               pool_free(fe->rsp_cap_pool, s->res_cap);
-               pool_free(fe->req_cap_pool, s->req_cap);
        }
 
        /* Cleanup all variable contexts. */