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 <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-10-19 09:10:00 +02:00 committed by mergify[bot]
parent 0f9087d05e
commit 0e96199a1c

View File

@ -282,6 +282,13 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret
if err != nil { if err != nil {
return nil, nil, err 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) volOptions.FsName, err = volOptions.getFsName(ctx)
if err != nil { if err != nil {