diff options
author | Jhon Honce <jhonce@redhat.com> | 2021-08-02 14:09:55 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2021-08-24 16:36:10 -0700 |
commit | 1dc6d14735eef1e51368103aefba3d7c704dcfe3 (patch) | |
tree | 61109c0b3d99cb3bcf85f53b0f8a837a995b0569 /pkg/bindings/system | |
parent | e9daaf62e3921b8c696f3abd92f001a9447c8aa1 (diff) | |
download | podman-1dc6d14735eef1e51368103aefba3d7c704dcfe3.tar.gz podman-1dc6d14735eef1e51368103aefba3d7c704dcfe3.tar.bz2 podman-1dc6d14735eef1e51368103aefba3d7c704dcfe3.zip |
Fix file descriptor leaks and add test
* Add response.Body.Close() where needed to release HTTP
connections to API server.
* Add tests to ensure no general leaks occur. 100% coverage would be
required to ensure no leaks on any call.
* Update code comments to be godoc correct
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/bindings/system')
-rw-r--r-- | pkg/bindings/system/info.go | 10 | ||||
-rw-r--r-- | pkg/bindings/system/system.go | 7 |
2 files changed, 11 insertions, 6 deletions
diff --git a/pkg/bindings/system/info.go b/pkg/bindings/system/info.go index 244f9643e..8a307a4ca 100644 --- a/pkg/bindings/system/info.go +++ b/pkg/bindings/system/info.go @@ -9,12 +9,7 @@ import ( ) // Info returns information about the libpod environment and its stores -func Info(ctx context.Context, options *InfoOptions) (*define.Info, error) { - if options == nil { - options = new(InfoOptions) - } - _ = options - info := define.Info{} +func Info(ctx context.Context, _ *InfoOptions) (*define.Info, error) { conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -23,5 +18,8 @@ func Info(ctx context.Context, options *InfoOptions) (*define.Info, error) { if err != nil { return nil, err } + defer response.Body.Close() + + info := define.Info{} return &info, response.Process(&info) } diff --git a/pkg/bindings/system/system.go b/pkg/bindings/system/system.go index 310bcef15..719cde52e 100644 --- a/pkg/bindings/system/system.go +++ b/pkg/bindings/system/system.go @@ -31,6 +31,8 @@ func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan if err != nil { return err } + defer response.Body.Close() + if cancelChan != nil { go func() { <-cancelChan @@ -75,6 +77,8 @@ func Prune(ctx context.Context, options *PruneOptions) (*entities.SystemPruneRep if err != nil { return nil, err } + defer response.Body.Close() + return &report, response.Process(&report) } @@ -101,6 +105,7 @@ func Version(ctx context.Context, options *VersionOptions) (*entities.SystemVers if err != nil { return nil, err } + defer response.Body.Close() if err = response.Process(&component); err != nil { return nil, err @@ -141,5 +146,7 @@ func DiskUsage(ctx context.Context, options *DiskOptions) (*entities.SystemDfRep if err != nil { return nil, err } + defer response.Body.Close() + return &report, response.Process(&report) } |