Avoid potential race when accessing size_map table
authorHans Boehm <boehm@acm.org>
Mon, 26 Feb 2018 20:45:24 +0000 (23:45 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 26 Feb 2018 20:45:24 +0000 (23:45 +0300)
commitf9c5815c132223139fc348166d861403e2196f47
treee7d4631d3555c611acf5709389b1d1cb2a90dccf
parent16c55506c5222ef40eba1e4aedf200358421080d
Avoid potential race when accessing size_map table

There is again a data race between GC_extend_size_map and GC_size_map[]
readers, though it is again not likely to fail in practice.

It is feasible to just move all of the GC_size_map accesses under the
lock, and this does not look to incur a substantial penalty.

* gcj_mlc.c (GC_gcj_malloc, GC_gcj_malloc_ignore_off_page): Move
lg=GC_size_map[lb] to be right after LOCK() instead of preceding it.
* malloc.c (GC_malloc_kind_global, GC_generic_malloc_uncollectable):
Likewise.
* typd_mlc.c (GC_malloc_explicitly_typed_ignore_off_page): Likewise.
* include/gc.h (GC_get_size_map_at): Update comment to note that the
client should use synchronization when calling the function.
* include/private/gc_priv.h (_GC_arrays._size_map): Add comment about
synchronization.
gcj_mlc.c
include/gc.h
include/private/gc_priv.h
malloc.c
typd_mlc.c