From ed71c28c37eda3ac3539144e8e415e0c7b8441a3 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Thu, 7 May 2015 19:12:23 -0700 Subject: [PATCH] Fixing panic in intelligent, attempted to delete nonexistent key --- pkg/storage/drivers/memory/memory_intelligent.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/storage/drivers/memory/memory_intelligent.go b/pkg/storage/drivers/memory/memory_intelligent.go index c3b6286c7..08e452017 100644 --- a/pkg/storage/drivers/memory/memory_intelligent.go +++ b/pkg/storage/drivers/memory/memory_intelligent.go @@ -134,12 +134,14 @@ func (r *Intelligent) Set(key string, value interface{}) { // Delete deletes a given key if exists func (r *Intelligent) Delete(key string) { - r.currentSize -= uint64(len(r.items[key].([]byte))) - delete(r.items, key) - delete(r.updatedAt, key) - r.totalEvicted++ - if r.OnEvicted != nil { - r.OnEvicted(key) + if _, ok := r.items[key]; ok { + r.currentSize -= uint64(len(r.items[key].([]byte))) + delete(r.items, key) + delete(r.updatedAt, key) + r.totalEvicted++ + if r.OnEvicted != nil { + r.OnEvicted(key) + } } }