Merge pull request #10327 from namreg/fix-grpcproxy-memory-leak

grpcproxy: fix memory leak
release-3.4
Xiang Li 2018-12-16 17:32:27 -08:00 committed by GitHub
commit abb57363ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -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: {}}
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)
}
}