Skip to content

Commit

Permalink
Merge pull request moby#14379 from Mashimiao/add-missing-stream-close
Browse files Browse the repository at this point in the history
api/client: close the returned io.ReadCloser
  • Loading branch information
calavera committed Jul 8, 2015
2 parents 2fe51ec + 91a4960 commit 159e830
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/client/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
return err
}

defer stream.Close()

var c types.ContainerJSON
if err := json.NewDecoder(stream).Decode(&c); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
return err
}

defer stream.Close()

if err := json.NewDecoder(stream).Decode(&response); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions api/client/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
return nil, err
}

defer stream.Close()

var response types.ContainerCreateResponse
if err := json.NewDecoder(stream).Decode(&response); err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions api/client/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func (cli *DockerCli) CmdDiff(args ...string) error {
return err
}

defer rdr.Close()

changes := []types.ContainerChange{}
if err := json.NewDecoder(rdr).Decode(&changes); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (cli *DockerCli) CmdExec(args ...string) error {
return err
}

defer stream.Close()

var response types.ContainerExecCreateResponse
if err := json.NewDecoder(stream).Decode(&response); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
return err
}

defer rdr.Close()

history := []types.ImageHistory{}
if err := json.NewDecoder(rdr).Decode(&history); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func (cli *DockerCli) CmdImages(args ...string) error {
return err
}

defer rdr.Close()

images := []types.Image{}
if err := json.NewDecoder(rdr).Decode(&images); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
return err
}

defer rdr.Close()

info := &types.Info{}
if err := json.NewDecoder(rdr).Decode(info); err != nil {
return fmt.Errorf("Error reading remote info: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions api/client/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
return err
}

defer stream.Close()

var response types.AuthResponse
if err := json.NewDecoder(stream).Decode(&response); err != nil {
// Upon error, remove entry
Expand Down
2 changes: 2 additions & 0 deletions api/client/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func (cli *DockerCli) CmdPort(args ...string) error {
return err
}

defer stream.Close()

var c struct {
NetworkSettings struct {
Ports nat.PortMap
Expand Down
2 changes: 2 additions & 0 deletions api/client/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (cli *DockerCli) CmdPs(args ...string) error {
return err
}

defer rdr.Close()

containers := []types.Container{}
if err := json.NewDecoder(rdr).Decode(&containers); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func (cli *DockerCli) CmdRmi(args ...string) error {
fmt.Fprintf(cli.err, "%s\n", err)
errNames = append(errNames, name)
} else {
defer rdr.Close()

dels := []types.ImageDelete{}
if err := json.NewDecoder(rdr).Decode(&dels); err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
Expand Down
2 changes: 2 additions & 0 deletions api/client/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
return err
}

defer rdr.Close()

results := ByStars{}
if err := json.NewDecoder(rdr).Decode(&results); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func (cli *DockerCli) CmdStart(args ...string) error {
return err
}

defer stream.Close()

var c types.ContainerJSON
if err := json.NewDecoder(stream).Decode(&c); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions api/client/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func (s *containerStats) Collect(cli *DockerCli, streamStats bool) {
s.mu.Unlock()
return
}

defer stream.Close()

var (
previousCPU uint64
previousSystem uint64
Expand Down
2 changes: 2 additions & 0 deletions api/client/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func (cli *DockerCli) CmdTop(args ...string) error {
return err
}

defer stream.Close()

procList := types.ContainerProcessList{}
if err := json.NewDecoder(stream).Decode(&procList); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions api/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func waitForExit(cli *DockerCli, containerID string) (int, error) {
return -1, err
}

defer stream.Close()

var res types.ContainerWaitResponse
if err := json.NewDecoder(stream).Decode(&res); err != nil {
return -1, err
Expand All @@ -270,6 +272,8 @@ func getExitCode(cli *DockerCli, containerID string) (bool, int, error) {
return false, -1, nil
}

defer stream.Close()

var c types.ContainerJSON
if err := json.NewDecoder(stream).Decode(&c); err != nil {
return false, -1, err
Expand All @@ -290,6 +294,8 @@ func getExecExitCode(cli *DockerCli, execID string) (bool, int, error) {
return false, -1, nil
}

defer stream.Close()

//TODO: Should we reconsider having a type in api/types?
//this is a response to exex/id/json not container
var c struct {
Expand Down
2 changes: 2 additions & 0 deletions api/client/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
return err
}

defer stream.Close()

var v types.Version
if err := json.NewDecoder(stream).Decode(&v); err != nil {
fmt.Fprintf(cli.err, "Error reading remote version: %s\n", err)
Expand Down

0 comments on commit 159e830

Please sign in to comment.