From 6d9de39ae2a7fe05bb9e36c9ee937d9283a46322 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 2 Dec 2022 15:32:35 +0300 Subject: [PATCH] Pull request: 5190-fix-panic Updates AdguardTeam/AdGuardHome#4695. Updates AdguardTeam/AdGuardHome#5190. Squashed commit of the following: commit 881fbc00e038ec30a9bf52f53a590e38687a399a Author: Ainar Garipov Date: Fri Dec 2 15:28:47 2022 +0300 proxy: fix panic --- proxy/cache.go | 8 ++++++-- proxy/cache_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/proxy/cache.go b/proxy/cache.go index 95d3034df..264e6bb4e 100644 --- a/proxy/cache.go +++ b/proxy/cache.go @@ -318,7 +318,9 @@ 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. @@ -326,7 +328,9 @@ 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. diff --git a/proxy/cache_test.go b/proxy/cache_test.go index b29e27c45..625b749e0 100644 --- a/proxy/cache_test.go +++ b/proxy/cache_test.go @@ -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)