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 *entry = cache->head;
|
||||||
struct MsgBuf_cache_entry *prev = NULL;
|
struct MsgBuf_cache_entry *prev = NULL;
|
||||||
struct MsgBuf_cache_entry *result = NULL;
|
struct MsgBuf_cache_entry *result = NULL;
|
||||||
|
struct MsgBuf_cache_entry *tail = NULL;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
while (entry != NULL) {
|
while (entry != NULL) {
|
||||||
|
@ -449,6 +450,7 @@ msgbuf_cache_get(struct MsgBuf_cache *cache, unsigned int caps)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tail = prev;
|
||||||
prev = entry;
|
prev = entry;
|
||||||
entry = entry->next;
|
entry = entry->next;
|
||||||
n++;
|
n++;
|
||||||
|
@ -462,6 +464,8 @@ msgbuf_cache_get(struct MsgBuf_cache *cache, unsigned int caps)
|
||||||
} else {
|
} else {
|
||||||
/* Cache full, replace the last entry */
|
/* Cache full, replace the last entry */
|
||||||
result = prev;
|
result = prev;
|
||||||
|
if (tail != NULL)
|
||||||
|
tail->next = NULL;
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
|
|
||||||
rb_linebuf_donebuf(&result->linebuf);
|
rb_linebuf_donebuf(&result->linebuf);
|
||||||
|
|
Loading…
Reference in a new issue