Skip to content

Commit

Permalink
grpcproxy: fix memory leak
Browse files Browse the repository at this point in the history
use set instead of slice as interval value

fixes etcd-io#1
  • Loading branch information
Igor German committed Dec 15, 2018
1 parent e57f4f4 commit 6a3e646
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions proxy/grpcproxy/cache/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 6a3e646

Please sign in to comment.