From 8c6548608115bc302356f54dceb7e8d3ab12b247 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 12 Jun 2019 11:08:11 +0200 Subject: [PATCH] BUG/MINOR: htx: Detect when tail_addr meet end_addr to maximize free rooms When a block's payload is moved during an expansion or when the whole block is removed, the addresses of free spaces are updated accordingly. We must be careful to reset them when becomes equal to . In this situation, we can maximize the free space between the blocks and their payload and set the other one to 0. It is also important to be sure to never have greater than . --- src/htx.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/htx.c b/src/htx.c index e83271cb3..bfd136f46 100644 --- a/src/htx.c +++ b/src/htx.c @@ -249,11 +249,17 @@ static int htx_prepare_blk_expansion(struct htx *htx, struct htx_blk *blk, int32 } else if ((sz + delta) < headroom) { /* Move the block's payload into the headroom */ - if (blk->addr == htx->end_addr) - htx->end_addr += sz; blk->addr = htx->head_addr; htx->tail_addr -= sz; htx->head_addr += sz + delta; + if (blk->addr == htx->end_addr) { + if (htx->end_addr == htx->tail_addr) { + htx->tail_addr = htx->head_addr; + htx->head_addr = htx->end_addr = 0; + } + else + htx->end_addr += sz; + } ret = 2; } } @@ -368,11 +374,13 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) htx->tail_addr = addr; else if (addr+sz == htx->head_addr) htx->head_addr = addr; - if (addr == htx->end_addr) - htx->end_addr += sz; - if (htx->tail_addr == htx->end_addr) { - htx->tail_addr = htx->head_addr; - htx->head_addr = htx->end_addr = 0; + if (addr == htx->end_addr) { + if (htx->tail_addr == htx->end_addr) { + htx->tail_addr = htx->head_addr; + htx->head_addr = htx->end_addr = 0; + } + else + htx->end_addr += sz; } }