From 7bd0edb9700409fb8709f49d3a866bd4d790655a Mon Sep 17 00:00:00 2001 From: John Sully Date: Thu, 9 Jul 2020 22:29:27 +0000 Subject: [PATCH] Fix race in db iterators in scan Former-commit-id: a6444870660c0d3f52cd7b1dc0b80223f0d58e70 --- src/dict.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dict.cpp b/src/dict.cpp index 0e8827165..ef7365fdb 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -952,7 +952,7 @@ unsigned long dictScan(dict *d, /* Having a safe iterator means no rehashing can happen, see _dictRehashStep. * This is needed in case the scan callback tries to do dictFind or alike. */ - d->iterators++; + __atomic_fetch_add(&d->iterators, 1, __ATOMIC_SEQ_CST); if (!dictIsRehashing(d)) { t0 = &(d->ht[0]); @@ -1021,7 +1021,7 @@ unsigned long dictScan(dict *d, } /* undo the ++ at the top */ - d->iterators--; + __atomic_fetch_sub(&d->iterators, 1, __ATOMIC_SEQ_CST); return v; }