From d41b3b0302591241b3c6cd786f6a1c7ee8538e0d Mon Sep 17 00:00:00 2001 From: Chapuis Bertil Date: Tue, 15 Sep 2015 18:30:09 +0200 Subject: [PATCH] nil http response can't be closed --- backend/rest/rest.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/rest/rest.go b/backend/rest/rest.go index ecfcc3198..22a012b66 100644 --- a/backend/rest/rest.go +++ b/backend/rest/rest.go @@ -64,7 +64,9 @@ func (rb *RestBlob) Finalize(t backend.Type, name string) error { <-rb.b.connChan client := *rb.b.client resp, err := client.Post(restPath(rb.b.url, t, name), "binary/octet-stream", rb.buf) - defer resp.Body.Close() + if resp != nil { + defer resp.Body.Close() + } if resp.StatusCode != 200 { err = errors.New("blob not saved") } @@ -151,7 +153,9 @@ func (b *Rest) Test(t backend.Type, name string) (bool, error) { } client := *b.client resp, err := client.Do(req) - defer resp.Body.Close() + if resp != nil { + defer resp.Body.Close() + } if err != nil { return false, err } @@ -169,7 +173,9 @@ func (b *Rest) Remove(t backend.Type, name string) error { } client := *b.client resp, err := client.Do(req) - defer resp.Body.Close() + if resp != nil { + defer resp.Body.Close() + } return err } @@ -186,7 +192,9 @@ func (b *Rest) List(t backend.Type, done <-chan struct{}) <-chan string { client := *b.client resp, err := client.Get(restPath(b.url, t, "")) - defer resp.Body.Close() + if resp != nil { + defer resp.Body.Close() + } if err != nil { close(ch) return ch