From 67d9fd9aa4176b367596f8e0885ad974cf8bffeb Mon Sep 17 00:00:00 2001 From: scx Date: Mon, 23 Sep 2019 01:19:56 +0200 Subject: [PATCH] DataBlockCache: Fix crash in cache invalidation (#142) The original version uses a reverse iterator, whose .base() is invalid after KillMacroBlock() erases it. --- src/block_cache.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/block_cache.h b/src/block_cache.h index 9fcaf42e7..8cc393a06 100644 --- a/src/block_cache.h +++ b/src/block_cache.h @@ -150,8 +150,11 @@ public: } // Remove old entries until we're under the max size - for (auto it = age.rbegin(); size > max_size && it != age.rend(); ) - KillMacroBlock(**it++); + while (size > max_size) { + // When size > 0, age should never be empty + assert(!age.empty()); + KillMacroBlock(**age.rbegin()); + } } /// @brief Obtain a data block from the cache