From: Ilya Dryomov Date: Tue, 18 Feb 2025 16:51:47 +0000 (+0100) Subject: test/rbd_mirror: clear Namespace::s_instance at the end of a test X-Git-Tag: v20.0.0~96^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F61880%2Fhead;p=ceph.git test/rbd_mirror: clear Namespace::s_instance at the end of a test TestMockPoolReplayer.Namespaces and NamespacesError tests leave behind a dangling pointer to a stack-allocated MockNamespace which leads to an easily reproducible use-after-free and segfault when tests are shuffled. Fixes: https://tracker.ceph.com/issues/70041 Signed-off-by: Ilya Dryomov --- diff --git a/src/test/rbd_mirror/test_mock_PoolReplayer.cc b/src/test/rbd_mirror/test_mock_PoolReplayer.cc index ec5d40f8705d..31540021eb5a 100644 --- a/src/test/rbd_mirror/test_mock_PoolReplayer.cc +++ b/src/test/rbd_mirror/test_mock_PoolReplayer.cc @@ -56,9 +56,15 @@ public: } Namespace() { + ceph_assert(s_instance == nullptr); s_instance = this; } + ~Namespace() { + ceph_assert(s_instance == this); + s_instance = nullptr; + } + void add(const std::string &name) { std::lock_guard locker{m_lock};