Skip to content

Commit 14c5178

Browse files
committed
MDEV-27069: heap-use-after-free in dict_stats_recalc_pool_del()
dict_stats_recalc_pool_del(): Always reposition the iterators after releasing and reacquiring the mutex. Another thread could have modified recalc_pool, causing reallocation of the underlying memory while we were waiting. This fixes a regression that was caused by commit 45a05fd (MDEV-25919).
1 parent 862eccd commit 14c5178

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

storage/innobase/dict/dict0stats_bg.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void dict_stats_recalc_pool_del(table_id_t id, bool have_mdl_exclusive)
216216

217217
mysql_mutex_lock(&recalc_pool_mutex);
218218

219-
const auto end= recalc_pool.end();
219+
auto end= recalc_pool.end();
220220
auto i= std::find_if(recalc_pool.begin(), end,
221221
[&](const recalc &r){return r.id == id;});
222222
if (i != end)
@@ -227,7 +227,14 @@ void dict_stats_recalc_pool_del(table_id_t id, bool have_mdl_exclusive)
227227
{
228228
i->state= recalc::IN_PROGRESS_DELETING;
229229
do
230+
{
230231
my_cond_wait(&recalc_pool_cond, &recalc_pool_mutex.m_mutex);
232+
end= recalc_pool.end();
233+
i= std::find_if(recalc_pool.begin(), end,
234+
[&](const recalc &r){return r.id == id;});
235+
if (i == end)
236+
goto done;
237+
}
231238
while (i->state == recalc::IN_PROGRESS_DELETING);
232239
}
233240
/* fall through */
@@ -241,6 +248,7 @@ void dict_stats_recalc_pool_del(table_id_t id, bool have_mdl_exclusive)
241248
}
242249
}
243250

251+
done:
244252
mysql_mutex_unlock(&recalc_pool_mutex);
245253
}
246254

0 commit comments

Comments
 (0)