From ca451098b2657a10fc758c7714d8edc969741306 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 14 Feb 2017 15:22:08 +0000 Subject: [PATCH] Update httpcache to fix memory leak --- vendor/manifest | 2 +- .../src/github.com/gregjones/httpcache/httpcache.go | 12 ++++++------ .../github.com/gregjones/httpcache/httpcache_test.go | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vendor/manifest b/vendor/manifest index 4eda44e..3070089 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -126,7 +126,7 @@ { "importpath": "github.com/gregjones/httpcache", "repository": "https://github.com/gregjones/httpcache", - "revision": "413781778738c08fdbb98e1dd65f5abffe8832d0", + "revision": "d02018f006d98f58512bf3adfc171d88d17626df", "branch": "master" }, { diff --git a/vendor/src/github.com/gregjones/httpcache/httpcache.go b/vendor/src/github.com/gregjones/httpcache/httpcache.go index 69842a7..ee6bf5c 100644 --- a/vendor/src/github.com/gregjones/httpcache/httpcache.go +++ b/vendor/src/github.com/gregjones/httpcache/httpcache.go @@ -223,22 +223,22 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error } if req2 != nil { // Associate original request with cloned request so we can refer to - // it in CancelRequest() + // it in CancelRequest(). Release the mapping when it's no longer needed. t.setModReq(req, req2) - req = req2 - defer func() { + defer func(originalReq *http.Request) { // Release req/clone mapping on error if err != nil { - t.setModReq(req, nil) + t.setModReq(originalReq, nil) } if resp != nil { // Release req/clone mapping on body close/EOF resp.Body = &onEOFReader{ rc: resp.Body, - fn: func() { t.setModReq(req, nil) }, + fn: func() { t.setModReq(originalReq, nil) }, } } - }() + }(req) + req = req2 } } } diff --git a/vendor/src/github.com/gregjones/httpcache/httpcache_test.go b/vendor/src/github.com/gregjones/httpcache/httpcache_test.go index 3fbe5c8..0ef7bab 100644 --- a/vendor/src/github.com/gregjones/httpcache/httpcache_test.go +++ b/vendor/src/github.com/gregjones/httpcache/httpcache_test.go @@ -465,6 +465,11 @@ func TestGetWithLastModified(t *testing.T) { if err != nil { t.Fatal(err) } + defer func() { + if len(s.transport.modReq) != 0 { + t.Errorf("Request-map is not empty") + } + }() { resp, err := s.client.Do(req) if err != nil {