Skip to content

Commit 0928a7a

Browse files
committed
HPCC-33586 Fix double-checked locking pattern in Dali
Change DFdir to be an atomic pointer for thread safety. Signed-off-by: Dave Streeter <[email protected]>
1 parent 0b1db29 commit 0928a7a

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

dali/base/dadfs.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -8239,20 +8239,22 @@ class CNamedGroupStore: implements INamedGroupStore, public CInterface
82398239

82408240
};
82418241

8242-
static CNamedGroupStore *groupStore = NULL;
8242+
static std::atomic<CNamedGroupStore *> groupStore{nullptr};
82438243
static CriticalSection groupsect;
82448244

82458245
bool CNamedGroupIterator::match()
82468246
{
82478247
if (conn.get()) {
82488248
if (matchgroup.get()) {
8249-
if (!groupStore)
8249+
CLeavableCriticalBlock block3(groupsect);
8250+
if (!groupStore.load())
82508251
return false;
82518252
const char *name = pe->query().queryProp("@name");
82528253
if (!name||!*name)
82538254
return false;
82548255
GroupType dummy;
8255-
Owned<IGroup> lgrp = groupStore->dolookup(name, conn, NULL, dummy);
8256+
Owned<IGroup> lgrp = groupStore.load()->dolookup(name, conn, NULL, dummy);
8257+
block3.leave();
82568258
if (lgrp) {
82578259
if (exactmatch)
82588260
return lgrp->equals(matchgroup);
@@ -8266,14 +8268,13 @@ bool CNamedGroupIterator::match()
82668268
return false;
82678269
}
82688270

8269-
INamedGroupStore &queryNamedGroupStore()
8271+
INamedGroupStore &queryNamedGroupStore()
82708272
{
8271-
if (!groupStore) {
8272-
CriticalBlock block(groupsect);
8273-
if (!groupStore)
8274-
groupStore = new CNamedGroupStore();
8273+
CriticalBlock block(groupsect);
8274+
if (!groupStore.load()) {
8275+
groupStore.store(new CNamedGroupStore());
82758276
}
8276-
return *groupStore;
8277+
return *(groupStore.load());
82778278
}
82788279

82798280
// --------------------------------------------------------
@@ -9244,8 +9245,8 @@ void closedownDFS() // called by dacoven
92449245
}
92459246
DFdir = NULL;
92469247
CriticalBlock block2(groupsect);
9247-
::Release(groupStore);
9248-
groupStore = NULL;
9248+
::Release(groupStore.load());
9249+
groupStore.store(nullptr);
92499250
}
92509251

92519252
class CDFPartFilter : implements IDFPartFilter, public CInterface

0 commit comments

Comments
 (0)