Skip to content

Commit

Permalink
Cleanup: Remove mem_block_t::magic_n and mem_block_validate()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Feb 3, 2020
1 parent 37b9734 commit a9d1324
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 46 deletions.
11 changes: 0 additions & 11 deletions storage/innobase/include/mem0mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 2 additions & 26 deletions storage/innobase/include/mem0mem.ic
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions storage/innobase/mem/mem0mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -422,16 +416,13 @@ 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);
heap->total_size -= block->len;

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);
Expand Down

0 comments on commit a9d1324

Please sign in to comment.