From: Daniel Gryniewicz Date: Wed, 17 Jun 2020 14:21:04 +0000 (-0400) Subject: NULL out g_ceph_context when deleting it X-Git-Tag: wip-pdonnell-testing-20200918.022351~631^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ede7561f4fe9e638211a6aa2e5baef3098008f34;p=ceph-ci.git 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 --- 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);