From 0e96199a1c0fbb8b1242ee852ad1b1fc4e04cb58 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Mon, 19 Oct 2020 09:10:00 +0200 Subject: [PATCH] cephfs: free resources when newVolumeOptionsFromVolID() errors out The allocated, and potentially connected, volumeOptions object in newVolumeOptionsFromVolID() is not cleaned-up in case of errors. This could cause resource leaks. Signed-off-by: Niels de Vos --- internal/cephfs/volumeoptions.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/cephfs/volumeoptions.go b/internal/cephfs/volumeoptions.go index f50626300..40f4a4d3e 100644 --- a/internal/cephfs/volumeoptions.go +++ b/internal/cephfs/volumeoptions.go @@ -282,6 +282,13 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret if err != nil { return nil, nil, err } + // in case of an error, volOptions is not returned, release any + // resources that may have been allocated + defer func() { + if err != nil { + volOptions.Destroy() + } + }() volOptions.FsName, err = volOptions.getFsName(ctx) if err != nil {