MEDIUM: buffer: use b_alloc() to allocate and initialize a buffer

b_alloc() now allocates a buffer and initializes it to the size specified
in the pool minus the size of the struct buffer itself. This ensures that
callers do not need to care about buffer details anymore. Also this never
applies memory poisonning, which is slow and useless on buffers.
diff --git a/include/common/buffer.h b/include/common/buffer.h
index fd29575..52565dd 100644
--- a/include/common/buffer.h
+++ b/include/common/buffer.h
@@ -395,6 +395,20 @@
 	buf->p = buf->data;
 }
 
+/* Allocates a buffer and replaces *buf with this buffer. No control is made
+ * to check if *buf already pointed to another buffer. The allocated buffer
+ * is returned, or NULL in case no memory is available.
+ */
+static inline struct buffer *b_alloc(struct buffer **buf)
+{
+	*buf = pool_alloc_dirty(pool2_buffer);
+	if (likely(*buf)) {
+		(*buf)->size = pool2_buffer->size - sizeof(struct buffer);
+		b_reset(*buf);
+	}
+	return *buf;
+}
+
 #endif /* _COMMON_BUFFER_H */
 
 /*
diff --git a/src/compression.c b/src/compression.c
index b6c4ae2..db2209a 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -137,8 +137,6 @@
 	/* We start by copying the current buffer's pending outgoing data into
 	 * a new temporary buffer that we initialize with a new empty chunk.
 	 */
-
-	out->size = global.tune.bufsize;
 	b_reset(out);
 
 	if (in->o > 0) {
diff --git a/src/peers.c b/src/peers.c
index 9ff1773..a5dff87 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -1237,11 +1237,9 @@
 	if ((s->req = pool_alloc2(pool2_channel)) == NULL)
 		goto out_fail_req; /* no memory */
 
-	if ((s->req->buf = pool_alloc2(pool2_buffer)) == NULL)
+	if (unlikely(b_alloc(&s->req->buf) == NULL))
 		goto out_fail_req_buf; /* no memory */
 
-	s->req->buf->size = global.tune.bufsize;
-	b_reset(s->req->buf);
 	channel_init(s->req);
 	s->req->prod = &s->si[0];
 	s->req->cons = &s->si[1];
@@ -1264,11 +1262,9 @@
 	if ((s->rep = pool_alloc2(pool2_channel)) == NULL)
 		goto out_fail_rep; /* no memory */
 
-	if ((s->rep->buf = pool_alloc2(pool2_buffer)) == NULL)
+	if (unlikely(b_alloc(&s->rep->buf) == NULL))
 		goto out_fail_rep_buf; /* no memory */
 
-	s->rep->buf->size = global.tune.bufsize;
-	b_reset(s->rep->buf);
 	channel_init(s->rep);
 	s->rep->prod = &s->si[1];
 	s->rep->cons = &s->si[0];
diff --git a/src/proto_http.c b/src/proto_http.c
index 3fffc5b..ee1a812 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -6572,8 +6572,7 @@
 		 */
 		if (unlikely(tmpbuf == NULL)) {
 			/* this is the first time we need the compression buffer */
-			tmpbuf = pool_alloc2(pool2_buffer);
-			if (tmpbuf == NULL)
+			if (b_alloc(&tmpbuf) == NULL)
 				goto aborted_xfer; /* no memory */
 		}
 
diff --git a/src/session.c b/src/session.c
index d57a2d5..05fd72e 100644
--- a/src/session.c
+++ b/src/session.c
@@ -477,18 +477,15 @@
 	if (unlikely((s->req = pool_alloc2(pool2_channel)) == NULL))
 		goto out_free_task; /* no memory */
 
-	if (unlikely((s->req->buf = pool_alloc2(pool2_buffer)) == NULL))
+	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((s->rep->buf = pool_alloc2(pool2_buffer)) == NULL))
+	if (unlikely(b_alloc(&s->rep->buf) == NULL))
 		goto out_free_rep; /* no memory */
 
-	/* initialize the request buffer */
-	s->req->buf->size = global.tune.bufsize;
-	b_reset(s->req->buf);
 	channel_init(s->req);
 	s->req->prod = &s->si[0];
 	s->req->cons = &s->si[1];
@@ -504,9 +501,6 @@
 	s->req->wex = TICK_ETERNITY;
 	s->req->analyse_exp = TICK_ETERNITY;
 
-	/* initialize response buffer */
-	s->rep->buf->size = global.tune.bufsize;
-	b_reset(s->rep->buf);
 	channel_init(s->rep);
 	s->rep->prod = &s->si[1];
 	s->rep->cons = &s->si[0];