Background threads: fix an indexing bug.

We have a buffer overrun that manifests in the case where arena indices higher
than the number of CPUs are accessed before arena indices lower than the number
of CPUs.  This fixes the bug and adds a test.
This commit is contained in:
David Goldblatt
2018-02-26 17:11:29 -08:00
committed by David Goldblatt
parent dd7e283b6f
commit 26b1c13982
3 changed files with 37 additions and 1 deletions

View File

@@ -600,7 +600,8 @@ background_threads_enable(tsd_t *tsd) {
arena_get(tsd_tsdn(tsd), i, false) == NULL) {
continue;
}
background_thread_info_t *info = &background_thread_info[i];
background_thread_info_t *info = &background_thread_info[
i % ncpus];
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
assert(info->state == background_thread_stopped);
background_thread_init(tsd, info);