Commit a0ce3216 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-16136 Various ASAN failures after MDEV-15030

The Pool poisoning that was introduced in MDEV-15030 introduced
race conditions in AddressSanitizer builds, because concurrent
poisoning and unpoisoning were not prevented by any synchronization
primitive.

Pool::get(): Protect the unpoisoning by m_lock_strategy.

Pool::mem_free(): Protect the poisoning by m_lock_strategy.

Pool::putl(): Renamed from put(), because now the caller is
responsible for invoking m_lock_strategy.
parent fa2a74e0
...@@ -125,8 +125,7 @@ struct Pool { ...@@ -125,8 +125,7 @@ struct Pool {
elem = NULL; elem = NULL;
} }
m_lock_strategy.exit(); #if defined HAVE_valgrind || defined __SANITIZE_ADDRESS__
if (elem) { if (elem) {
/* Unpoison the memory for AddressSanitizer */ /* Unpoison the memory for AddressSanitizer */
MEM_UNDEFINED(&elem->m_type, sizeof elem->m_type); MEM_UNDEFINED(&elem->m_type, sizeof elem->m_type);
...@@ -135,10 +134,11 @@ struct Pool { ...@@ -135,10 +134,11 @@ struct Pool {
actually initialized; we checked that by actually initialized; we checked that by
UNIV_MEM_ASSERT_RW() in mem_free() below. */ UNIV_MEM_ASSERT_RW() in mem_free() below. */
UNIV_MEM_VALID(&elem->m_type, sizeof elem->m_type); UNIV_MEM_VALID(&elem->m_type, sizeof elem->m_type);
return &elem->m_type;
} }
#endif
return NULL; m_lock_strategy.exit();
return elem ? &elem->m_type : NULL;
} }
/** Add the object to the pool. /** Add the object to the pool.
...@@ -151,8 +151,12 @@ struct Pool { ...@@ -151,8 +151,12 @@ struct Pool {
elem = reinterpret_cast<Element*>(p - sizeof(*elem)); elem = reinterpret_cast<Element*>(p - sizeof(*elem));
UNIV_MEM_ASSERT_RW(&elem->m_type, sizeof elem->m_type); UNIV_MEM_ASSERT_RW(&elem->m_type, sizeof elem->m_type);
elem->m_pool->put(elem); elem->m_pool->m_lock_strategy.enter();
elem->m_pool->putl(elem);
MEM_NOACCESS(&elem->m_type, sizeof elem->m_type); MEM_NOACCESS(&elem->m_type, sizeof elem->m_type);
elem->m_pool->m_lock_strategy.exit();
} }
protected: protected:
...@@ -170,17 +174,13 @@ struct Pool { ...@@ -170,17 +174,13 @@ struct Pool {
/** Release the object to the free pool /** Release the object to the free pool
@param elem element to free */ @param elem element to free */
void put(Element* elem) void putl(Element* elem)
{ {
m_lock_strategy.enter();
ut_ad(elem >= m_start && elem < m_last); ut_ad(elem >= m_start && elem < m_last);
ut_ad(Factory::debug(&elem->m_type)); ut_ad(Factory::debug(&elem->m_type));
m_pqueue.push(elem); m_pqueue.push(elem);
m_lock_strategy.exit();
} }
/** Initialise the elements. /** Initialise the elements.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment