diff options
author | Javi Fontan <jfontan@gmail.com> | 2019-02-25 11:42:09 +0100 |
---|---|---|
committer | Javi Fontan <jfontan@gmail.com> | 2019-02-25 15:10:24 +0100 |
commit | e9d0393809be173a2b28cb1a60b306468464c7fb (patch) | |
tree | da147d38dde5940994928e3d7096704fff4edc10 /plumbing/cache/object_lru.go | |
parent | db6c41c156481962abf9a55a324858674c25ab08 (diff) | |
download | go-git-e9d0393809be173a2b28cb1a60b306468464c7fb.tar.gz |
plumbing/cache: check for empty cache list
If there is wrong data in the cache it may cause the eviction code to
empty the object list and cause a panic. This patch adds a check and
sets the cache usage to 0 when this happens.
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/cache/object_lru.go')
-rw-r--r-- | plumbing/cache/object_lru.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/plumbing/cache/object_lru.go b/plumbing/cache/object_lru.go index 53d8b02..cd3712b 100644 --- a/plumbing/cache/object_lru.go +++ b/plumbing/cache/object_lru.go @@ -61,6 +61,11 @@ func (c *ObjectLRU) Put(obj plumbing.EncodedObject) { c.actualSize += objSize for c.actualSize > c.MaxSize { last := c.ll.Back() + if last == nil { + c.actualSize = 0 + break + } + lastObj := last.Value.(plumbing.EncodedObject) lastSize := FileSize(lastObj.Size()) |