Skip to content

Commit 63d0b53

Browse files
rbd: make Destroy nil-safe and remove redundant nil checks
Signed-off-by: Niraj Yadav <niryadav@redhat.com>
1 parent ad1e097 commit 63d0b53

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

internal/rbd/manager.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ func (mgr *rbdManager) GetVolumeByID(ctx context.Context, id string) (types.Volu
7575

7676
volume, err := GenVolFromVolID(ctx, id, creds, mgr.secrets)
7777
if err != nil {
78-
if volume != nil {
79-
volume.Destroy(ctx)
80-
}
78+
volume.Destroy(ctx)
8179

8280
switch {
8381
case errors.Is(err, rbderrors.ErrImageNotFound):
@@ -100,9 +98,7 @@ func (mgr *rbdManager) GetSnapshotByID(ctx context.Context, id string) (types.Sn
10098

10199
snapshot, err := genSnapFromSnapID(ctx, id, creds, mgr.secrets)
102100
if err != nil {
103-
if snapshot != nil {
104-
snapshot.Destroy(ctx)
105-
}
101+
snapshot.Destroy(ctx)
106102

107103
switch {
108104
case errors.Is(err, rbderrors.ErrImageNotFound):

internal/rbd/rbd_util.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ func (ri *rbdImage) Connect(cr *util.Credentials) error {
420420
// Destroy cleans up the rbdVolume and closes the connection to the Ceph
421421
// cluster in case one was setup.
422422
func (ri *rbdImage) Destroy(ctx context.Context) {
423+
if ri == nil {
424+
return
425+
}
423426
if ri.ioctx != nil {
424427
ri.ioctx.Destroy()
425428
ri.ioctx = nil

0 commit comments

Comments
 (0)