8298293: NMT: os::realloc() should verify that flags do not change between reallocations

Reviewed-by: dholmes, stuefe, iklam
This commit is contained in:
Gerard Ziemski 2023-02-13 18:14:31 +00:00
parent 101db262e1
commit c37e9d1c8d
3 changed files with 8 additions and 6 deletions

View file

@ -694,7 +694,7 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
// Special handling for NMT preinit phase before arguments are parsed
void* rc = nullptr;
if (NMTPreInit::handle_realloc(&rc, memblock, size)) {
if (NMTPreInit::handle_realloc(&rc, memblock, size, memflags)) {
return rc;
}
@ -727,6 +727,8 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
// Perform integrity checks on and mark the old block as dead *before* calling the real realloc(3) since it
// may invalidate the old block, including its header.
MallocHeader* header = MallocHeader::resolve_checked(memblock);
assert(memflags == header->flags(), "weird NMT flags mismatch (new:\"%s\" != old:\"%s\")\n",
NMTUtil::flag_to_name(memflags), NMTUtil::flag_to_name(header->flags()));
const MallocHeader::FreeInfo free_info = header->free_info();
header->mark_block_as_dead();