From 8c252d58eacd04fe2d43e59c451abcf71882d87b Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 25 Sep 2024 11:36:32 +0200 Subject: [PATCH] rbd: prevent re-use of destroyed resources When an `.Destroy()` is called on an rbdImage (or rbdVolume or rbdSnapshot), the IOContext, Connection and other attributes are invalid. When using a destroyed resource that points to an object that was allocated through librbd, the process most likely ends with a panic. Signed-off-by: Niels de Vos --- internal/rbd/rbd_util.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index e363e391c..65b2b5728 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -390,15 +390,19 @@ func (ri *rbdImage) Connect(cr *util.Credentials) error { func (ri *rbdImage) Destroy(ctx context.Context) { if ri.ioctx != nil { ri.ioctx.Destroy() + ri.ioctx = nil } if ri.conn != nil { ri.conn.Destroy() + ri.conn = nil } if ri.isBlockEncrypted() { ri.blockEncryption.Destroy() + ri.blockEncryption = nil } if ri.isFileEncrypted() { ri.fileEncryption.Destroy() + ri.fileEncryption = nil } }