From bbd24e52f39b2d1ae55062c82398b803f9bb4ba4 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 15 Mar 2021 10:58:29 +0100 Subject: [PATCH] cleanup: use rbdImage.Destroy() for temporary volumes rbdVolumes can have several resources that get allocated during its usage. Only destroying the IOContext may not be suffiecient and can cause resource leaks. Use rbdVolume.Destroy() when the rbdVolume is not used anymore. Signed-off-by: Niels de Vos --- internal/rbd/rbd_util.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 8769877a6..f99009046 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -493,6 +493,8 @@ func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er func (rv *rbdVolume) getCloneDepth(ctx context.Context) (uint, error) { var depth uint vol := rbdVolume{} + defer vol.Destroy() + vol.Pool = rv.Pool vol.Monitors = rv.Monitors vol.RbdImageName = rv.RbdImageName @@ -503,9 +505,6 @@ func (rv *rbdVolume) getCloneDepth(ctx context.Context) (uint, error) { return depth, err } - defer func() { - vol.ioctx.Destroy() - }() for { if vol.RbdImageName == "" { return depth, nil @@ -662,6 +661,8 @@ func (rv *rbdVolume) hasFeature(feature uint64) bool { func (rv *rbdVolume) checkImageChainHasFeature(ctx context.Context, feature uint64) (bool, error) { vol := rbdVolume{} + defer vol.Destroy() + vol.Pool = rv.Pool vol.RadosNamespace = rv.RadosNamespace vol.Monitors = rv.Monitors @@ -672,7 +673,6 @@ func (rv *rbdVolume) checkImageChainHasFeature(ctx context.Context, feature uint if err != nil { return false, err } - defer vol.ioctx.Destroy() for { if vol.RbdImageName == "" {