From f0d83c4cdb49adb53fdaf4216a4395c23d5cc8e9 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Wed, 16 Mar 2016 16:38:13 +0100 Subject: [PATCH] *: fix response body leaks Signed-off-by: Antonio Murdaca --- api/client/build.go | 1 + daemon/graphdriver/proxy.go | 1 - daemon/logger/splunk/splunk.go | 4 +--- pkg/plugins/client.go | 1 + registry/session.go | 1 + 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/client/build.go b/api/client/build.go index eef716a99e..dde61ac220 100644 --- a/api/client/build.go +++ b/api/client/build.go @@ -236,6 +236,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if err != nil { return err } + defer response.Body.Close() err = jsonmessage.DisplayJSONMessagesStream(response.Body, buildBuff, cli.outFd, cli.isTerminalOut, nil) if err != nil { diff --git a/daemon/graphdriver/proxy.go b/daemon/graphdriver/proxy.go index 47128473b0..28657fef16 100644 --- a/daemon/graphdriver/proxy.go +++ b/daemon/graphdriver/proxy.go @@ -161,7 +161,6 @@ func (d *graphDriverProxy) Diff(id, parent string) (archive.Archive, error) { } body, err := d.client.Stream("GraphDriver.Diff", args) if err != nil { - body.Close() return nil, err } return archive.Archive(body), nil diff --git a/daemon/logger/splunk/splunk.go b/daemon/logger/splunk/splunk.go index 706478aa94..201905f364 100644 --- a/daemon/logger/splunk/splunk.go +++ b/daemon/logger/splunk/splunk.go @@ -174,9 +174,7 @@ func (l *splunkLogger) Log(msg *logger.Message) error { if err != nil { return err } - if res.Body != nil { - defer res.Body.Close() - } + defer res.Body.Close() if res.StatusCode != http.StatusOK { var body []byte body, err = ioutil.ReadAll(res.Body) diff --git a/pkg/plugins/client.go b/pkg/plugins/client.go index b54d6f2273..0d6be2399b 100644 --- a/pkg/plugins/client.go +++ b/pkg/plugins/client.go @@ -101,6 +101,7 @@ func (c *Client) SendFile(serviceMethod string, data io.Reader, ret interface{}) if err != nil { return err } + defer body.Close() if err := json.NewDecoder(body).Decode(&ret); err != nil { logrus.Errorf("%s: error reading plugin resp: %v", serviceMethod, err) return err diff --git a/registry/session.go b/registry/session.go index bd0dfb2cbd..5647ad2864 100644 --- a/registry/session.go +++ b/registry/session.go @@ -284,6 +284,7 @@ func (r *Session) GetRemoteImageLayer(imgID, registry string, imgSize int64) (io res, err = r.client.Do(req) if err != nil { logrus.Debugf("Error contacting registry %s: %v", registry, err) + // the only case err != nil && res != nil is https://golang.org/src/net/http/client.go#L515 if res != nil { if res.Body != nil { res.Body.Close()