From 6a3e646a140c1bbcab943d11fee66c70b79e43d3 Mon Sep 17 00:00:00 2001 From: Igor German Date: Sat, 15 Dec 2018 15:35:11 +0300 Subject: [PATCH] grpcproxy: fix memory leak use set instead of slice as interval value fixes #1 --- proxy/grpcproxy/cache/store.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/proxy/grpcproxy/cache/store.go b/proxy/grpcproxy/cache/store.go index af369fe69920..4c2df18b1cfe 100644 --- a/proxy/grpcproxy/cache/store.go +++ b/proxy/grpcproxy/cache/store.go @@ -99,9 +99,12 @@ func (c *cache) Add(req *pb.RangeRequest, resp *pb.RangeResponse) { iv = c.cachedRanges.Find(ivl) if iv == nil { - c.cachedRanges.Insert(ivl, []string{key}) + val := map[string]struct{}{key: struct{}{}} + c.cachedRanges.Insert(ivl, val) } else { - iv.Val = append(iv.Val.([]string), key) + val := iv.Val.(map[string]struct{}) + val[key] = struct{}{} + iv.Val = val } } @@ -141,8 +144,8 @@ func (c *cache) Invalidate(key, endkey []byte) { ivs = c.cachedRanges.Stab(ivl) for _, iv := range ivs { - keys := iv.Val.([]string) - for _, key := range keys { + keys := iv.Val.(map[string]struct{}) + for key := range keys { c.lru.Remove(key) } }