diff --git a/doc/internals/buffer-api.txt b/doc/internals/buffer-api.txt index 13881f7eb..abb5e9f76 100644 --- a/doc/internals/buffer-api.txt +++ b/doc/internals/buffer-api.txt @@ -568,10 +568,10 @@ b_alloc_fast | buffer *buf | allocates a buffer and assigns it to | | even if some memory is available --------------------+------------------+--------------------------------------- __b_drop | buffer *buf | releases which must be allocated - | ret: void | + | ret: void | and marks it empty --------------------+------------------+--------------------------------------- b_drop | buffer *buf | releases only if it is allocated - | ret: void | + | ret: void | and marks it empty --------------------+------------------+--------------------------------------- b_free | buffer *buf | releases only if it is allocated | ret: void | and marks it empty diff --git a/include/common/buffer.h b/include/common/buffer.h index 3d6c97ca6..34a3e95d2 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -109,13 +109,22 @@ static inline struct buffer *b_alloc_fast(struct buffer *buf) return buf; } -/* Releases buffer (no check of emptiness) */ +/* Releases buffer (no check of emptiness). The buffer's head is marked + * empty. + */ static inline void __b_drop(struct buffer *buf) { - pool_free(pool_head_buffer, buf->area); + char *area = buf->area; + + /* let's first clear the area to save an occasional "show sess all" + * glancing over our shoulder from getting a dangling pointer. + */ + *buf = BUF_NULL; + __ha_barrier_store(); + pool_free(pool_head_buffer, area); } -/* Releases buffer if allocated. */ +/* Releases buffer if allocated, and marks it empty. */ static inline void b_drop(struct buffer *buf) { if (buf->size) @@ -126,7 +135,6 @@ static inline void b_drop(struct buffer *buf) static inline void b_free(struct buffer *buf) { b_drop(buf); - *buf = BUF_NULL; } /* Ensures that is allocated. If an allocation is needed, it ensures that