1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Fixed wrong assignment in calculate_block_sizes() for MEM_ROOT

The effect was that that ROOT_FLAG_THREAD_SPECIFIC was cleared and
the memory allocated by memroot would be contributed the the system,
not to the thread.

This exposed a bug in how "show explain for ..." allocated data.
- The thread that did provide the explain allocated data in the
  "show explain" threads mem_root, which is marked as THREAD_SPECIFIC.
- Fixed by allocating the explain data in a temporary explain_mem_root
  which is not THREAD_SPECIFIC.

Other things:
- Added extra checks when using update_malloc_size()
- Do not call update_malloc_size() for memory not registered with
  update_malloc_size(). This avoid some wrong 'memory not freed' reports.
- Added a checking of 'thd->killed' to ensure that
  main.truncate_notembedded.test still works.

Reported by: Yury Chaikou
This commit is contained in:
Monty
2023-06-12 20:11:32 +03:00
parent c4cf5e17ac
commit e1a631fecc
5 changed files with 54 additions and 18 deletions

View File

@@ -99,7 +99,7 @@ static void calculate_block_sizes(MEM_ROOT *mem_root, size_t block_size,
{
size_t pre_alloc= *pre_alloc_size;
if (mem_root->flags&= ROOT_FLAG_MPROTECT)
if (mem_root->flags & ROOT_FLAG_MPROTECT)
{
mem_root->block_size= MY_ALIGN(block_size, my_system_page_size);
if (pre_alloc)
@@ -159,6 +159,8 @@ void init_alloc_root(PSI_memory_key key, MEM_ROOT *mem_root, size_t block_size,
mem_root->min_malloc= 32 + REDZONE_SIZE;
mem_root->block_size= MY_MAX(block_size, ROOT_MIN_BLOCK_SIZE);
mem_root->flags= 0;
DBUG_ASSERT(!test_all_bits(mem_root->flags,
(MY_THREAD_SPECIFIC | MY_ROOT_USE_MPROTECT)));
if (my_flags & MY_THREAD_SPECIFIC)
mem_root->flags|= ROOT_FLAG_THREAD_SPECIFIC;
if (my_flags & MY_ROOT_USE_MPROTECT)