From 9b7336575bf6bfa4b2683289308fea2670dfa3e3 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sat, 23 Jun 2018 10:40:11 +0300 Subject: Maintain correct ordering of the avail table after coalescing. * src/falloc.c (_gdbm_put_av_elem): Float the merged entry to its proper position to preserve the sorting order. * THANKS: Thanks Adam Sampson --- src/falloc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/falloc.c b/src/falloc.c index 6571d9b..2fb8ea1 100644 --- a/src/falloc.c +++ b/src/falloc.c @@ -427,9 +427,20 @@ _gdbm_put_av_elem (avail_elem new_el, avail_elem av_table[], int *av_count, index++; continue; } - - /* If we got here, we're done. */ - return TRUE; + + /* Coalescing breaks the sorting order, so we need to + restore it */ + while (index + 1 < *av_count + && av_table[index].av_size > av_table[index + 1].av_size) + { + avail_elem t = av_table[index]; + av_table[index] = av_table[index + 1]; + av_table[index + 1] = t; + index++; + } + + /* we're done. */ + return TRUE; } } -- cgit v1.2.1