diff --git a/include/haproxy/chunk.h b/include/haproxy/chunk.h index 341b33940..7c9350f7b 100644 --- a/include/haproxy/chunk.h +++ b/include/haproxy/chunk.h @@ -165,9 +165,7 @@ static forceinline struct buffer *alloc_small_trash_chunk(void) */ static forceinline struct buffer *alloc_trash_chunk_sz(size_t size) { - if (pool_head_small_trash && size <= pool_head_small_trash->size) - return alloc_small_trash_chunk(); - else if (size <= pool_head_trash->size) + if (size <= pool_head_trash->size) return alloc_trash_chunk(); else if (pool_head_large_trash && size <= pool_head_large_trash->size) return alloc_large_trash_chunk(); diff --git a/src/chunk.c b/src/chunk.c index fd95b9687..ab4f002b1 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -145,14 +145,15 @@ struct buffer *get_small_trash_chunk(void) /* Returns a trash chunk accordingly to the requested size. This function may * fail if the requested size is too big or if the large chunks are not - * configured. + * configured. Note that requesting a size larger than the largest available + * buffer will result in NULL being returned, so better be conservative when + * requesting the size and plan to use get_larger_trash_chunk() later if not + * sufficient. */ struct buffer *get_trash_chunk_sz(size_t size) { - if (likely(size > small_trash_size && size <= trash_size)) + if (likely(size <= trash_size)) return get_trash_chunk(); - else if (small_trash_size && size <= small_trash_size) - return get_small_trash_chunk(); else if (large_trash_size && size <= large_trash_size) return get_large_trash_chunk(); else