Browse Source

*: fix response body leaks

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Antonio Murdaca 9 years ago
parent
commit
f0d83c4cdb

+ 1 - 0
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 {

+ 0 - 1
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

+ 1 - 3
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)

+ 1 - 0
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

+ 1 - 0
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()