From ede7561f4fe9e638211a6aa2e5baef3098008f34 Mon Sep 17 00:00:00 2001 From: Daniel Gryniewicz Date: Wed, 17 Jun 2020 10:21:04 -0400 Subject: [PATCH] NULL out g_ceph_context when deleting it This avoids a use-after-free when there is a crash on shutdown (or when something like ASAN triggers an ABORT on leak). Signed-off-by: Daniel Gryniewicz --- src/common/ceph_context.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index d4248d9e9b1..2e46507955c 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -782,6 +782,8 @@ void CephContext::put() { if (--nref == 0) { ANNOTATE_HAPPENS_AFTER(&nref); ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&nref); + if (g_ceph_context == this) + g_ceph_context = nullptr; delete this; } else { ANNOTATE_HAPPENS_BEFORE(&nref); -- 2.39.5