MEDIUM: buffer: add a new buf_wanted dummy buffer to report failed allocations
Doing so ensures that even when no memory is available, we leave the
channel in a sane condition. There's a special case in proto_http.c
regarding the compression, we simply pre-allocate the tmpbuf to point
to the dummy buffer. Not reusing &buf_empty for this allows the rest
of the code to differenciate an empty buffer that's not used from an
empty buffer that results from a failed allocation which has the same
semantics as a buffer full.
diff --git a/src/proto_http.c b/src/proto_http.c
index ee1a812..b4861ce 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -6516,7 +6516,7 @@
{
struct http_txn *txn = &s->txn;
struct http_msg *msg = &s->txn.rsp;
- static struct buffer *tmpbuf = NULL;
+ static struct buffer *tmpbuf = &buf_empty;
int compressing = 0;
int ret;
@@ -6570,7 +6570,7 @@
* output of compressed data, and in CRLF state to let the
* TRAILERS state finish the job of removing the trailing CRLF.
*/
- if (unlikely(tmpbuf == NULL)) {
+ if (unlikely(!tmpbuf->size)) {
/* this is the first time we need the compression buffer */
if (b_alloc(&tmpbuf) == NULL)
goto aborted_xfer; /* no memory */