Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Close open connections and files (#135)
Browse files Browse the repository at this point in the history
Ensure that the client and file is closed either in error cases or once cleanup() is called so no file descriptors are leaked.
  • Loading branch information
bastianccm authored Sep 29, 2020
1 parent 1b5f79c commit 719c92b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions image/daemon/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func Image(ref name.Reference) (v1.Image, func(), error) {
if err != nil {
return nil, cleanup, xerrors.Errorf("failed to initialize a docker client: %w", err)
}
defer func() {
if err != nil {
c.Close()
}
}()

inspect, _, err := c.ImageInspectWithRaw(context.Background(), ref.Name())
if err != nil {
Expand All @@ -50,6 +55,8 @@ func Image(ref name.Reference) (v1.Image, func(), error) {
}

cleanup = func() {
c.Close()
f.Close()
_ = os.Remove(f.Name())
}

Expand Down

0 comments on commit 719c92b

Please sign in to comment.