Commit a9d13248 authored by Marko Mäkelä's avatar Marko Mäkelä

Cleanup: Remove mem_block_t::magic_n and mem_block_validate()

Use of freed memory is better caught by AddressSanitizer,
especially with ASAN_POISON_MEMORY_REGION that is aliased
by MEM_NOACCESS and UNIV_MEM_FREE.
parent 37b9734c
......@@ -287,13 +287,6 @@ mem_heap_printf(
const char* format, /*!< in: format string */
...) MY_ATTRIBUTE ((format (printf, 2, 3)));
/** Checks that an object is a memory heap (or a block of it)
@param[in] heap Memory heap to check */
UNIV_INLINE
void
mem_block_validate(
const mem_heap_t* heap);
#ifdef UNIV_DEBUG
/** Validates the contents of a memory heap.
Asserts that the memory heap is consistent
......@@ -308,7 +301,6 @@ mem_heap_validate(
/** The info structure stored at the beginning of a heap block */
struct mem_block_info_t {
ulint magic_n;/* magic number for debugging */
#ifdef UNIV_DEBUG
char file_name[8];/* file name where the mem heap was created */
unsigned line; /*!< line number where the mem heap was created */
......@@ -343,9 +335,6 @@ struct mem_block_info_t {
otherwise, this is NULL */
};
#define MEM_BLOCK_MAGIC_N 764741555
#define MEM_FREED_BLOCK_MAGIC_N 547711122
/* Header size for a memory heap block */
#define MEM_BLOCK_HEADER_SIZE UT_CALC_ALIGN(sizeof(mem_block_info_t),\
UNIV_MEM_ALIGNMENT)
......
/*****************************************************************************
Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -144,16 +144,6 @@ mem_block_get_start(mem_block_t* block)
return(block->start);
}
/** Checks that an object is a memory heap block
@param[in] block Memory block to check. */
UNIV_INLINE
void
mem_block_validate(
const mem_block_t* block)
{
ut_a(block->magic_n == MEM_BLOCK_MAGIC_N);
}
/** Allocates and zero-fills n bytes of memory from a memory heap.
@param[in] heap memory heap
@param[in] n number of bytes; if the heap is allowed to grow into
......@@ -186,8 +176,6 @@ mem_heap_alloc(
byte* buf;
ulint free;
ut_d(mem_block_validate(heap));
block = UT_LIST_GET_LAST(heap->base);
n += REDZONE_SIZE;
......@@ -230,8 +218,6 @@ mem_heap_get_heap_top(
mem_block_t* block;
byte* buf;
ut_d(mem_block_validate(heap));
block = UT_LIST_GET_LAST(heap->base);
buf = (byte*) block + mem_block_get_free(block);
......@@ -321,8 +307,6 @@ mem_heap_get_top(
mem_block_t* block;
byte* buf;
ut_d(mem_block_validate(heap));
block = UT_LIST_GET_LAST(heap->base);
buf = (byte*) block + mem_block_get_free(block) - MEM_SPACE_NEEDED(n);
......@@ -342,8 +326,6 @@ mem_heap_free_top(
{
mem_block_t* block;
ut_d(mem_block_validate(heap));
n += REDZONE_SIZE;
block = UT_LIST_GET_LAST(heap->base);
......@@ -419,8 +401,6 @@ mem_heap_free(
mem_block_t* block;
mem_block_t* prev_block;
ut_d(mem_block_validate(heap));
block = UT_LIST_GET_LAST(heap->base);
if (heap->free_block) {
......@@ -447,11 +427,7 @@ mem_heap_get_size(
/*==============*/
mem_heap_t* heap) /*!< in: heap */
{
ulint size = 0;
ut_d(mem_block_validate(heap));
size = heap->total_size;
ulint size = heap->total_size;
if (heap->free_block) {
size += UNIV_PAGE_SIZE;
......
......@@ -222,8 +222,6 @@ mem_heap_validate(
block != NULL;
block = UT_LIST_GET_NEXT(list, block)) {
mem_block_validate(block);
switch (block->type) {
case MEM_HEAP_DYNAMIC:
break;
......@@ -278,7 +276,6 @@ mem_heap_create_block_func(
|| (type == MEM_HEAP_BUFFER + MEM_HEAP_BTR_SEARCH));
if (heap != NULL) {
mem_block_validate(heap);
ut_d(mem_heap_validate(heap));
}
......@@ -320,7 +317,6 @@ mem_heap_create_block_func(
block->buf_block = buf_block;
block->free_block = NULL;
block->magic_n = MEM_BLOCK_MAGIC_N;
ut_d(ut_strlcpy_rev(block->file_name, file_name,
sizeof(block->file_name)));
ut_d(block->line = line);
......@@ -368,8 +364,6 @@ mem_heap_add_block(
mem_block_t* new_block;
ulint new_size;
ut_d(mem_block_validate(heap));
block = UT_LIST_GET_LAST(heap->base);
/* We have to allocate a new block. The size is always at least
......@@ -422,8 +416,6 @@ mem_heap_block_free(
buf_block = static_cast<buf_block_t*>(block->buf_block);
mem_block_validate(block);
UT_LIST_REMOVE(heap->base, block);
ut_ad(heap->total_size >= block->len);
......@@ -431,7 +423,6 @@ mem_heap_block_free(
type = heap->type;
len = block->len;
block->magic_n = MEM_FREED_BLOCK_MAGIC_N;
if (type == MEM_HEAP_DYNAMIC || len < UNIV_PAGE_SIZE / 2) {
ut_ad(!buf_block);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment