msgbuf_cache_get: Don't create cycle when evicting
This commit is contained in:
parent
73d8a5aa23
commit
888d20da6d
1 changed files with 4 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue