]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: move buffer initialization after channel initialization
authorWilly Tarreau <w@1wt.eu>
Mon, 24 Nov 2014 10:36:57 +0000 (11:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Dec 2014 22:47:32 +0000 (23:47 +0100)
It's not clean to initialize the buffer before the channel since it
dereferences one pointer in the channel. Also we'll want to let the
channel pre-initialize the buffer, so let's ensure that the channel
is always initialized prior to the buffers.

src/peers.c
src/session.c

index a5dff87e60f0214bda89466d7581b193b23c6cb5..af413c69a4de4d3b6db53549067decbb1237adcf 100644 (file)
@@ -1237,9 +1237,6 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
        if ((s->req = pool_alloc2(pool2_channel)) == NULL)
                goto out_fail_req; /* no memory */
 
-       if (unlikely(b_alloc(&s->req->buf) == NULL))
-               goto out_fail_req_buf; /* no memory */
-
        channel_init(s->req);
        s->req->prod = &s->si[0];
        s->req->cons = &s->si[1];
@@ -1259,12 +1256,12 @@ 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 */
 
-       if (unlikely(b_alloc(&s->rep->buf) == NULL))
-               goto out_fail_rep_buf; /* no memory */
-
        channel_init(s->rep);
        s->rep->prod = &s->si[1];
        s->rep->cons = &s->si[0];
@@ -1282,6 +1279,10 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
        t->expire = TICK_ETERNITY;
 
        s->rep->flags |= CF_READ_DONTWAIT;
+
+       if (unlikely(b_alloc(&s->rep->buf) == NULL))
+               goto out_fail_rep_buf; /* no memory */
+
        /* it is important not to call the wakeup function directly but to
         * pass through task_wakeup(), because this one knows how to apply
         * priorities to tasks.
index 05fd72e56ca92015d12e94e1be3b2698b8ddd9be..6770ee484585b78af91a9dcf161e318dd40f6001 100644 (file)
@@ -477,15 +477,6 @@ int session_complete(struct session *s)
        if (unlikely((s->req = pool_alloc2(pool2_channel)) == NULL))
                goto out_free_task; /* no memory */
 
-       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 */
-
-       if (unlikely(b_alloc(&s->rep->buf) == NULL))
-               goto out_free_rep; /* no memory */
-
        channel_init(s->req);
        s->req->prod = &s->si[0];
        s->req->cons = &s->si[1];
@@ -501,6 +492,12 @@ 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 */
+
        channel_init(s->rep);
        s->rep->prod = &s->si[1];
        s->rep->cons = &s->si[0];
@@ -518,6 +515,9 @@ 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))
+               goto out_free_rep; /* 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