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

Commit

Permalink
Merge pull request #2176 from allencloud/close-http-response-body-to-…
Browse files Browse the repository at this point in the history
…avoid-memory-leak

close http response body to avoid potential memory leak
  • Loading branch information
abronan committed Apr 29, 2016
2 parents 9dd2985 + b5a74ee commit dd90e08
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 @@ -1023,8 +1025,11 @@ 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 dd90e08

Please sign in to comment.