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 a863c02
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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 @@ -1025,6 +1027,9 @@ func (e *Engine) Load(reader io.Reader) error {

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

loadResponse.Body.Close()

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

0 comments on commit a863c02

Please sign in to comment.