msgbuf_cache_get: Don't create cycle when evicting

This commit is contained in:
Ed Kellett 2021-05-19 14:44:55 +01:00
parent 73d8a5aa23
commit 888d20da6d

View file

@ -440,6 +440,7 @@ msgbuf_cache_get(struct MsgBuf_cache *cache, unsigned int caps)
struct MsgBuf_cache_entry *entry = cache->head;
struct MsgBuf_cache_entry *prev = NULL;
struct MsgBuf_cache_entry *result = NULL;
struct MsgBuf_cache_entry *tail = NULL;
int n = 0;
while (entry != NULL) {
@ -449,6 +450,7 @@ msgbuf_cache_get(struct MsgBuf_cache *cache, unsigned int caps)
break;
}
tail = prev;
prev = entry;
entry = entry->next;
n++;
@ -462,6 +464,8 @@ msgbuf_cache_get(struct MsgBuf_cache *cache, unsigned int caps)
} else {
/* Cache full, replace the last entry */
result = prev;
if (tail != NULL)
tail->next = NULL;
prev = NULL;
rb_linebuf_donebuf(&result->linebuf);