]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: htx: Detect when tail_addr meet end_addr to maximize free rooms
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 12 Jun 2019 09:08:11 +0000 (11:08 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 14 Jun 2019 09:13:32 +0000 (11:13 +0200)
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 <tail_addr> becomes equal to <end_addr>. 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
<end_addr> greater than <tail_addr>.

src/htx.c

index e83271cb3c74aafa2508fb4c3c119f2fac01d6ef..bfd136f460cf07df172acb882fd56569118d0f47 100644 (file)
--- 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;
                }
        }