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/connection.go | |
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/connection.go')
-rw-r--r-- | pkg/bindings/connection.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go index cd118cbb2..4127ad2f0 100644 --- a/pkg/bindings/connection.go +++ b/pkg/bindings/connection.go @@ -56,7 +56,7 @@ func NewConnection(ctx context.Context, uri string) (context.Context, error) { return NewConnectionWithIdentity(ctx, uri, "") } -// NewConnection takes a URI as a string and returns a context with the +// NewConnectionWithIdentity takes a URI as a string and returns a context with the // Connection embedded as a value. This context needs to be passed to each // endpoint to work correctly. // @@ -149,6 +149,7 @@ func pingNewConnection(ctx context.Context) error { if err != nil { return err } + defer response.Body.Close() if response.StatusCode == http.StatusOK { versionHdr := response.Header.Get("Libpod-API-Version") @@ -338,7 +339,7 @@ func (c *Connection) DoRequest(httpBody io.Reader, httpMethod, endpoint string, req.Header.Set(key, val) } // Give the Do three chances in the case of a comm/service hiccup - for i := 0; i < 3; i++ { + for i := 1; i <= 3; i++ { response, err = c.Client.Do(req) // nolint if err == nil { break @@ -358,7 +359,7 @@ func FiltersToString(filters map[string][]string) (string, error) { return jsoniter.MarshalToString(lowerCaseKeys) } -// IsInformation returns true if the response code is 1xx +// IsInformational returns true if the response code is 1xx func (h *APIResponse) IsInformational() bool { return h.Response.StatusCode/100 == 1 } |