diff --git a/doc/internals/buffer-api.txt b/doc/internals/buffer-api.txt index d4e26dbd99..a163e387ae 100644 --- a/doc/internals/buffer-api.txt +++ b/doc/internals/buffer-api.txt @@ -547,13 +547,12 @@ buffer_almost_full | const buffer *buf| returns true if the buffer is not null | ret: int | and at least 3/4 of the buffer's space | | are used. A waiting buffer will match. --------------------+------------------+--------------------------------------- -b_alloc | buffer *buf | allocates a buffer and assigns it to - | ret: buffer * | *buf. If no memory is available, (1) +b_alloc | buffer *buf | ensures that is allocated or + | ret: buffer * | allocates a buffer and assigns it to + | | *buf. If no memory is available, (1) | | is assigned instead with a zero size. - | | 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 + | | The allocated buffer is returned, or + | | NULL in case no memory is available --------------------+------------------+--------------------------------------- b_alloc_fast | buffer *buf | allocates a buffer and assigns it to | ret: buffer * | *buf. If no memory is available, (1) diff --git a/include/haproxy/dynbuf.h b/include/haproxy/dynbuf.h index c31b83aaac..00e5fff508 100644 --- a/include/haproxy/dynbuf.h +++ b/include/haproxy/dynbuf.h @@ -56,15 +56,17 @@ static inline int buffer_almost_full(const struct buffer *buf) /* Functions below are used for buffer allocation */ /**************************************************/ -/* Allocates a buffer and assigns it to *buf. If no memory is available, - * ((char *)1) is assigned instead with a zero size. No control is made to - * check if *buf already pointed to another buffer. The allocated buffer is +/* Ensures that is allocated, or allocates it. If no memory is available, + * ((char *)1) is assigned instead with a zero size. The allocated buffer is * returned, or NULL in case no memory is available. */ static inline struct buffer *b_alloc(struct buffer *buf) { char *area; + if (buf->size) + return buf; + *buf = BUF_WANTED; area = pool_alloc_dirty(pool_head_buffer); if (unlikely(!area)) {