summaryrefslogtreecommitdiff
path: root/pkg/bindings/manifests/manifests.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2021-08-02 14:09:55 -0700
committerJhon Honce <jhonce@redhat.com>2021-08-24 16:36:10 -0700
commit1dc6d14735eef1e51368103aefba3d7c704dcfe3 (patch)
tree61109c0b3d99cb3bcf85f53b0f8a837a995b0569 /pkg/bindings/manifests/manifests.go
parente9daaf62e3921b8c696f3abd92f001a9447c8aa1 (diff)
downloadpodman-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/manifests/manifests.go')
-rw-r--r--pkg/bindings/manifests/manifests.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/pkg/bindings/manifests/manifests.go b/pkg/bindings/manifests/manifests.go
index 268ce3b19..6aa4961f1 100644
--- a/pkg/bindings/manifests/manifests.go
+++ b/pkg/bindings/manifests/manifests.go
@@ -46,10 +46,12 @@ func Create(ctx context.Context, names, images []string, options *CreateOptions)
if err != nil {
return "", err
}
+ defer response.Body.Close()
+
return idr.ID, response.Process(&idr)
}
-// Exists returns true if a given maifest list exists
+// Exists returns true if a given manifest list exists
func Exists(ctx context.Context, name string, options *ExistsOptions) (bool, error) {
conn, err := bindings.GetClient(ctx)
if err != nil {
@@ -59,6 +61,8 @@ func Exists(ctx context.Context, name string, options *ExistsOptions) (bool, err
if err != nil {
return false, err
}
+ defer response.Body.Close()
+
return response.IsSuccess(), nil
}
@@ -77,6 +81,8 @@ func Inspect(ctx context.Context, name string, options *InspectOptions) (*manife
if err != nil {
return nil, err
}
+ defer response.Body.Close()
+
return &list, response.Process(&list)
}
@@ -100,6 +106,8 @@ func Add(ctx context.Context, name string, options *AddOptions) (string, error)
if err != nil {
return "", err
}
+ defer response.Body.Close()
+
return idr.ID, response.Process(&idr)
}
@@ -121,6 +129,8 @@ func Remove(ctx context.Context, name, digest string, options *RemoveOptions) (s
if err != nil {
return "", err
}
+ defer response.Body.Close()
+
return idr.ID, response.Process(&idr)
}
@@ -145,18 +155,20 @@ func Push(ctx context.Context, name, destination string, options *images.PushOpt
if err != nil {
return "", err
}
- //SkipTLSVerify is special. We need to delete the param added by
- //toparams and change the key and flip the bool
+ // SkipTLSVerify is special. We need to delete the param added by
+ // toparams and change the key and flip the bool
if options.SkipTLSVerify != nil {
params.Del("SkipTLSVerify")
params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify()))
}
params.Set("image", name)
params.Set("destination", destination)
- _, err = conn.DoRequest(nil, http.MethodPost, "/manifests/%s/push", params, nil, name)
+ response, err := conn.DoRequest(nil, http.MethodPost, "/manifests/%s/push", params, nil, name)
if err != nil {
return "", err
}
+ defer response.Body.Close()
+
return idr.ID, err
}
@@ -179,5 +191,6 @@ func Push(ctx context.Context, name, destination string, options *images.PushOpt
// if err != nil {
// return "", err
// }
+// defer response.Body.Close()
// return idr.ID, response.Process(&idr)
//}