Skip to content

Commit a0ce321

Browse files
committed
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.
1 parent fa2a74e commit a0ce321

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

storage/innobase/include/ut0pool.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ struct Pool {
125125
elem = NULL;
126126
}
127127

128-
m_lock_strategy.exit();
129-
128+
#if defined HAVE_valgrind || defined __SANITIZE_ADDRESS__
130129
if (elem) {
131130
/* Unpoison the memory for AddressSanitizer */
132131
MEM_UNDEFINED(&elem->m_type, sizeof elem->m_type);
@@ -135,10 +134,11 @@ struct Pool {
135134
actually initialized; we checked that by
136135
UNIV_MEM_ASSERT_RW() in mem_free() below. */
137136
UNIV_MEM_VALID(&elem->m_type, sizeof elem->m_type);
138-
return &elem->m_type;
139137
}
138+
#endif
140139

141-
return NULL;
140+
m_lock_strategy.exit();
141+
return elem ? &elem->m_type : NULL;
142142
}
143143

144144
/** Add the object to the pool.
@@ -151,8 +151,12 @@ struct Pool {
151151
elem = reinterpret_cast<Element*>(p - sizeof(*elem));
152152
UNIV_MEM_ASSERT_RW(&elem->m_type, sizeof elem->m_type);
153153

154-
elem->m_pool->put(elem);
154+
elem->m_pool->m_lock_strategy.enter();
155+
156+
elem->m_pool->putl(elem);
155157
MEM_NOACCESS(&elem->m_type, sizeof elem->m_type);
158+
159+
elem->m_pool->m_lock_strategy.exit();
156160
}
157161

158162
protected:
@@ -170,17 +174,13 @@ struct Pool {
170174

171175
/** Release the object to the free pool
172176
@param elem element to free */
173-
void put(Element* elem)
177+
void putl(Element* elem)
174178
{
175-
m_lock_strategy.enter();
176-
177179
ut_ad(elem >= m_start && elem < m_last);
178180

179181
ut_ad(Factory::debug(&elem->m_type));
180182

181183
m_pqueue.push(elem);
182-
183-
m_lock_strategy.exit();
184184
}
185185

186186
/** Initialise the elements.

0 commit comments

Comments
 (0)