From: Ed Kellett Date: Wed, 19 May 2021 13:44:55 +0000 (+0100) Subject: msgbuf_cache_get: Don't create cycle when evicting X-Git-Url: https://jfr.im/git/solanum.git/commitdiff_plain/888d20da6d178e734ad5a2f938dc4f6966927feb msgbuf_cache_get: Don't create cycle when evicting --- diff --git a/ircd/msgbuf.c b/ircd/msgbuf.c index 46bf88af..a801ff62 100644 --- a/ircd/msgbuf.c +++ b/ircd/msgbuf.c @@ -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);