From 1d435a3e2e0542f9be0ca753ddafb3d70a48a6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 1 Oct 2020 19:18:11 +0200 Subject: [PATCH] Ensure that cache file is closed after reading --- api/cache.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/cache.go b/api/cache.go index 79d446ae2..006362504 100644 --- a/api/cache.go +++ b/api/cache.go @@ -84,11 +84,13 @@ func readCache(ttl time.Duration, cacheFile string, req *http.Request) (*http.Re } res, err := http.ReadResponse(bufio.NewReader(f), req) - if res != nil { + if res == nil { res.Body = &readCloser{ Reader: res.Body, Closer: f, } + } else { + f.Close() } return res, err }