]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
NULL out g_ceph_context when deleting it
authorDaniel Gryniewicz <dang@redhat.com>
Wed, 17 Jun 2020 14:21:04 +0000 (10:21 -0400)
committerDaniel Gryniewicz <dang@redhat.com>
Fri, 17 Jul 2020 16:05:49 +0000 (12:05 -0400)
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 <dang@redhat.com>
src/common/ceph_context.cc

index d4248d9e9b1d9d288547a72f7710013dc91b4c7f..2e46507955c7bcc63711698c0e28c6fb3267b870 100644 (file)
@@ -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);