Skip to content

Commit

Permalink
Pull request: 5190-fix-panic
Browse files Browse the repository at this point in the history
Updates AdguardTeam/AdGuardHome#4695.
Updates AdguardTeam/AdGuardHome#5190.

Squashed commit of the following:

commit 881fbc0
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 2 15:28:47 2022 +0300

    proxy: fix panic
  • Loading branch information
ainar-g committed Dec 2, 2022
1 parent 7aa32db commit 6d9de39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions proxy/cache.go
Expand Up @@ -318,15 +318,19 @@ func (c *cache) clearItems() {
c.itemsLock.Lock()
defer c.itemsLock.Unlock()

c.items.Clear()
if c.items != nil {
c.items.Clear()
}
}

// clearItemsWithSubnet empties the subnet cache.
func (c *cache) clearItemsWithSubnet() {
c.itemsWithSubnetLock.Lock()
defer c.itemsWithSubnetLock.Unlock()

c.itemsWithSubnet.Clear()
if c.itemsWithSubnet != nil {
c.itemsWithSubnet.Clear()
}
}

// cacheTTL returns the number of seconds for which m is valid to be cached.
Expand Down
2 changes: 1 addition & 1 deletion proxy/cache_test.go
Expand Up @@ -146,8 +146,8 @@ func TestCache_expired(t *testing.T) {
key := msgToKey(reply)
data := (&cacheItem{
m: reply,
ttl: tc.ttl,
u: testUpsAddr,
ttl: tc.ttl,
}).pack()
testCache.items.Set(key, data)
t.Cleanup(testCache.items.Clear)
Expand Down

0 comments on commit 6d9de39

Please sign in to comment.