BUG/MINOR: stream: only free the req/res captures when set

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.
This commit is contained in:
Willy Tarreau 2022-06-23 11:46:14 +02:00
parent aa55640b8c
commit 47af317389

View 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. */