From: Christos Tsantilas Date: Wed, 15 May 2013 16:43:04 +0000 (+0300) Subject: LruMap bug fix and other polishing touches X-Git-Tag: SQUID_3_4_0_1~137 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0cef2d4b48e2274def660eadaa565005c17fa574;p=thirdparty%2Fsquid.git LruMap bug fix and other polishing touches The LruMap::findEntry may return destroyed entries to the caller. --- diff --git a/src/base/LruMap.h b/src/base/LruMap.h index f018b70b41..506b0e0bf2 100644 --- a/src/base/LruMap.h +++ b/src/base/LruMap.h @@ -59,7 +59,7 @@ private: LruMap(LruMap const &); LruMap & operator = (LruMap const &); - bool expired(Entry &e); + bool expired(const Entry &e) const; void trim(); void touch(const MapIterator &i); bool del(const MapIterator &i); @@ -110,12 +110,14 @@ LruMap::findEntry(const char *key, LruMap::MapIterator &i index.erase(i->second); i->second = index.begin(); - Entry *e = *i->second; - - if (e && expired(*e)) { - del(i); - e = NULL; + if (const Entry *e = *i->second) { + if (!expired(*e)) + return; + // else fall through to cleanup } + + del(i); + i = storage.end(); } template @@ -124,9 +126,9 @@ LruMap::get(const char *key) { MapIterator i; findEntry(key, i); - Entry *e = *i->second; if (i != storage.end()) { touch(i); + Entry *e = *i->second; return e->value; } return NULL; @@ -150,7 +152,7 @@ LruMap::add(const char *key, EntryValue *t) template bool -LruMap::expired(LruMap::Entry &entry) +LruMap::expired(const LruMap::Entry &entry) const { if (ttl < 0) return false; @@ -163,9 +165,10 @@ bool LruMap::del(LruMap::MapIterator const &i) { if (i != storage.end()) { - delete *(i->second); + LruMap::Entry *e = *i->second; index.erase(i->second); storage.erase(i); + delete e; --entries_; return true; }