Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
close http response body to avoid potential memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Sun Hongliang <[email protected]>
  • Loading branch information
allencloud committed Apr 27, 2016
1 parent d0bc183 commit f793a28
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cluster/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,14 +988,16 @@ func (e *Engine) Pull(image string, authConfig *types.AuthConfig) error {
if err != nil {
return err
}
pullResponse, err := e.apiClient.ImagePull(context.Background(), pullOpts, nil)
pullResponseBody, err := e.apiClient.ImagePull(context.Background(), pullOpts, nil)
e.CheckConnectionErr(err)
if err != nil {
return err
}

defer pullResponseBody.Close()

// wait until the image download is finished
dec := json.NewDecoder(pullResponse)
dec := json.NewDecoder(pullResponseBody)
m := map[string]interface{}{}
for {
if err := dec.Decode(&m); err != nil {
Expand Down Expand Up @@ -1023,8 +1025,10 @@ func (e *Engine) Load(reader io.Reader) error {
return err
}

defer loadResponse.Body.Close()
// wait until the image load is finished
dec := json.NewDecoder(loadResponse.Body)

m := map[string]interface{}{}
for {
if err := dec.Decode(&m); err != nil {
Expand Down

0 comments on commit f793a28

Please sign in to comment.