Fix memory leak

As documented in https://github.com/karlseguin/ccache/issues/76, an entry which
is both GC'd and deleted (either via a delete or an update) will result in the
internal link list having a nil tail (because removing the same node multiple times
from the linked list does that).

doDelete was already aware of "invalid" nodes (where item.node == nil), so the
solution seems to be as simple as setting item.node = nil during GC.
This commit is contained in:
Karl Seguin
2022-11-19 08:15:48 +08:00
parent 4d3a63decc
commit 3452e4e261
4 changed files with 50 additions and 0 deletions

View File

@@ -438,6 +438,7 @@ func (c *Cache[T]) gc() int {
c.onDelete(item)
}
dropped += 1
item.node = nil
item.promotions = -2
}
node = prev