Fix race in db iterators in scan

Former-commit-id: a6444870660c0d3f52cd7b1dc0b80223f0d58e70
This commit is contained in:
John Sully 2020-07-09 22:29:27 +00:00
parent ecea6ffe67
commit 7bd0edb970

View File

@ -952,7 +952,7 @@ unsigned long dictScan(dict *d,
/* Having a safe iterator means no rehashing can happen, see _dictRehashStep. /* 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. */ * 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)) { if (!dictIsRehashing(d)) {
t0 = &(d->ht[0]); t0 = &(d->ht[0]);
@ -1021,7 +1021,7 @@ unsigned long dictScan(dict *d,
} }
/* undo the ++ at the top */ /* undo the ++ at the top */
d->iterators--; __atomic_fetch_sub(&d->iterators, 1, __ATOMIC_SEQ_CST);
return v; return v;
} }