From 937f5bac69b62a1fc703aab7eac506b4740fcc3c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 25 Nov 2014 19:54:11 +0100 Subject: MINOR: sessions: group buffer allocations together We'll soon want to release buffers together upon failure so we need to allocate them after the channels. Let's change this now. There's no impact on the behaviour, only the error path is unrolled slightly differently. The same was done in peers. --- src/peers.c | 10 +++++----- src/session.c | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/peers.c b/src/peers.c index 5371e49..84356e6 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1256,9 +1256,6 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio s->req->rto = s->fe->timeout.client; s->req->wto = s->be->timeout.server; - if (unlikely(b_alloc(&s->req->buf) == NULL)) - goto out_fail_req_buf; /* no memory */ - if ((s->rep = pool_alloc2(pool2_channel)) == NULL) goto out_fail_rep; /* no memory */ @@ -1280,6 +1277,9 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio s->rep->flags |= CF_READ_DONTWAIT; + if (unlikely(b_alloc(&s->req->buf) == NULL)) + goto out_fail_req_buf; /* no memory */ + if (unlikely(b_alloc(&s->rep->buf) == NULL)) goto out_fail_rep_buf; /* no memory */ @@ -1300,10 +1300,10 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio /* Error unrolling */ out_fail_rep_buf: - pool_free2(pool2_channel, s->rep); - out_fail_rep: b_free(&s->req->buf); out_fail_req_buf: + pool_free2(pool2_channel, s->rep); + out_fail_rep: pool_free2(pool2_channel, s->req); out_fail_req: conn_free(conn); diff --git a/src/session.c b/src/session.c index ebe992b..fbeb9cf 100644 --- a/src/session.c +++ b/src/session.c @@ -492,11 +492,8 @@ int session_complete(struct session *s) s->req->wex = TICK_ETERNITY; s->req->analyse_exp = TICK_ETERNITY; - if (unlikely(b_alloc(&s->req->buf) == NULL)) - goto out_free_req; /* no memory */ - if (unlikely((s->rep = pool_alloc2(pool2_channel)) == NULL)) - goto out_free_req_buf; /* no memory */ + goto out_free_req; /* no memory */ channel_init(s->rep); s->rep->prod = &s->si[1]; @@ -515,9 +512,12 @@ int session_complete(struct session *s) s->rep->wex = TICK_ETERNITY; s->rep->analyse_exp = TICK_ETERNITY; - if (unlikely(b_alloc(&s->rep->buf) == NULL)) + if (unlikely(b_alloc(&s->req->buf) == NULL)) goto out_free_rep; /* no memory */ + if (unlikely(b_alloc(&s->rep->buf) == NULL)) + goto out_free_req_buf; /* no memory */ + txn = &s->txn; /* Those variables will be checked and freed if non-NULL in * session.c:session_free(). It is important that they are @@ -566,10 +566,10 @@ int session_complete(struct session *s) /* Error unrolling */ out_free_rep_buf: b_free(&s->rep->buf); - out_free_rep: - pool_free2(pool2_channel, s->rep); out_free_req_buf: b_free(&s->req->buf); + out_free_rep: + pool_free2(pool2_channel, s->rep); out_free_req: pool_free2(pool2_channel, s->req); out_free_task: -- 1.7.12.1