]> jfr.im git - solanum.git/commitdiff
msgbuf_cache_get: Don't create cycle when evicting
authorEd Kellett <redacted>
Wed, 19 May 2021 13:44:55 +0000 (14:44 +0100)
committerEd Kellett <redacted>
Tue, 8 Jun 2021 21:00:26 +0000 (22:00 +0100)
ircd/msgbuf.c

index 46bf88af84d173fdcfc2d942c069c855ef4f0739..a801ff626ca428ddb2ef020d07cc0098774c7629 100644 (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);