From 024ade638ed66e97acd336669cb31465e6a012d7 Mon Sep 17 00:00:00 2001 From: huangzy Date: Tue, 18 Jul 2023 18:43:18 +0800 Subject: [PATCH] fix when rbdVol is nil, panic occurred Signed-off-by: huangzy --- internal/rbd/controllerserver.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index bd00d148f6b0..a9b1a8146888 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -1078,7 +1078,9 @@ func (cs *ControllerServer) CreateSnapshot( // Fetch source volume information rbdVol, err := GenVolFromVolID(ctx, req.GetSourceVolumeId(), cr, req.GetSecrets()) - defer rbdVol.Destroy() + if rbdVol != nil { + defer rbdVol.Destroy() + } if err != nil { switch { case errors.Is(err, ErrImageNotFound):