From 223506145988c88424a94f7264dabebaf35d8f2d Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Sun, 3 Oct 2021 14:05:56 -0400 Subject: [PATCH] GeoModelKernel: Fix race in RCBase::unref(). The decrement and test must be done atomically; otherwise we could have a race. E.g., suppose a RCBase object has a refcount of 2, and two threads call unref simultaneously. The two decrements could both happen before either of the comparisons, resulting in a double-delete. --- GeoModelCore/GeoModelKernel/src/RCBase.cxx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/GeoModelCore/GeoModelKernel/src/RCBase.cxx b/GeoModelCore/GeoModelKernel/src/RCBase.cxx index 1fedd9386..368cf3679 100755 --- a/GeoModelCore/GeoModelKernel/src/RCBase.cxx +++ b/GeoModelCore/GeoModelKernel/src/RCBase.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/RCBase.h" @@ -21,10 +21,7 @@ void RCBase::ref () const void RCBase::unref () const { - if (m_count.load()>0) { - m_count--; - if (m_count.load()==0) delete this; - } + if (--m_count == 0) delete this; } unsigned int RCBase::refCount () const -- GitLab