IndexedMemPool: Fix race condition on size_ that can cause the destructor to access...
authorMaged Michael <magedmichael@fb.com>
Thu, 6 Apr 2017 10:04:20 +0000 (03:04 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 6 Apr 2017 10:21:02 +0000 (03:21 -0700)
commitbba519bfb1b4c4d24fd210696e31fcf5e25d13e8
tree3c42d56a455e91d1722f4f2e53c55ec4302d99e2
parent674533ad47f61e0151bc298869fa7696c8147c94
IndexedMemPool: Fix race condition on size_ that can cause the destructor to access nonexistent slots

Summary:
Contention on allocation when there is exactly one slot remaining can cause size_ to exceed actualCapacity_.
Without taking the min of size_ and actualCapacity_ the destructor may try to destroy out-of-bound slots.

Added a test to test/IndexedMemPoolTest.cpp that failed before the fix and passes after the fix.

Reviewed By: nbronson

Differential Revision: D4837251

fbshipit-source-id: a887487727f17eaf2ba66345f40fc91d2fe3bc00
folly/IndexedMemPool.h
folly/test/IndexedMemPoolTest.cpp