From 0c753627542d287070987934e83a9e0243a364c8 Mon Sep 17 00:00:00 2001 From: Alice Thum Date: Mon, 8 Jun 2020 09:23:41 -0400 Subject: [PATCH] Use limit for purging --- digest.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/digest.go b/digest.go index d866b6b..3eaaf7a 100644 --- a/digest.go +++ b/digest.go @@ -80,7 +80,13 @@ func (da *DigestAuth) Purge(count int) { } cache := digestCache(entries) sort.Sort(cache) - for _, client := range cache[:count] { + + limit := count + if len(cache) < count { + limit = len(cache) - 1 + } + + for _, client := range cache[:limit] { delete(da.clients, client.nonce) } }