summaryrefslogtreecommitdiff
path: root/innobase/mem
diff options
context:
space:
mode:
authorunknown <heikki@donna.mysql.fi>2002-01-28 22:18:49 +0200
committerunknown <heikki@donna.mysql.fi>2002-01-28 22:18:49 +0200
commitac540e96a915c30034a4fc03ef65b60b8392f664 (patch)
treeaa7f771761883b28925048ff5e37e2eb85d77c00 /innobase/mem
parent2aa572433b9ce47a511958ce263c8400c2e81ac3 (diff)
downloadmariadb-git-ac540e96a915c30034a4fc03ef65b60b8392f664.tar.gz
Many files:
Merge InnoDB-.48 sql/ha_innobase.cc: Merge InnoDB-.48 innobase/include/dict0dict.h: Merge InnoDB-.48 innobase/include/dict0mem.h: Merge InnoDB-.48 innobase/include/mem0dbg.h: Merge InnoDB-.48 innobase/include/mem0mem.h: Merge InnoDB-.48 innobase/include/que0que.h: Merge InnoDB-.48 innobase/include/row0mysql.h: Merge InnoDB-.48 innobase/include/srv0srv.h: Merge InnoDB-.48 innobase/include/trx0sys.h: Merge InnoDB-.48 innobase/include/trx0trx.h: Merge InnoDB-.48 innobase/include/mem0mem.ic: Merge InnoDB-.48 innobase/dict/dict0dict.c: Merge InnoDB-.48 innobase/dict/dict0mem.c: Merge InnoDB-.48 innobase/log/log0recv.c: Merge InnoDB-.48 innobase/mem/mem0dbg.c: Merge InnoDB-.48 innobase/mem/mem0mem.c: Merge InnoDB-.48 innobase/pars/lexyy.c: Merge InnoDB-.48 innobase/que/que0que.c: Merge InnoDB-.48 innobase/rem/rem0rec.c: Merge InnoDB-.48 innobase/row/row0mysql.c: Merge InnoDB-.48 innobase/row/row0sel.c: Merge InnoDB-.48 innobase/srv/srv0srv.c: Merge InnoDB-.48 innobase/sync/sync0arr.c: Merge InnoDB-.48 innobase/trx/trx0sys.c: Merge InnoDB-.48 innobase/trx/trx0trx.c: Merge InnoDB-.48 innobase/trx/trx0undo.c: Merge InnoDB-.48
Diffstat (limited to 'innobase/mem')
-rw-r--r--innobase/mem/mem0dbg.c94
-rw-r--r--innobase/mem/mem0mem.c32
2 files changed, 110 insertions, 16 deletions
diff --git a/innobase/mem/mem0dbg.c b/innobase/mem/mem0dbg.c
index 0d71708b906..f8f62dffa8b 100644
--- a/innobase/mem/mem0dbg.c
+++ b/innobase/mem/mem0dbg.c
@@ -808,7 +808,7 @@ mem_validate_no_assert(void)
}
mutex_exit(&mem_hash_mutex);
-
+
return(error);
#else
@@ -832,3 +832,95 @@ mem_validate(void)
return(TRUE);
}
+
+/****************************************************************
+Tries to find neigboring memory allocation blocks and dumps to stderr
+the neighborhood of a given pointer. */
+
+void
+mem_analyze_corruption(
+/*===================*/
+ byte* ptr) /* in: pointer to place of possible corruption */
+{
+ byte* p;
+ ulint i;
+ ulint dist;
+
+ ut_sprintf_buf(srv_fatal_errbuf, ptr - 250, 500);
+ fprintf(stderr,
+ "InnoDB: Apparent memory corruption: mem dump %s\n", srv_fatal_errbuf);
+
+ fprintf(stderr,
+ "InnoDB: Scanning backward trying to find previous allocated mem blocks\n");
+
+ p = ptr;
+ dist = 0;
+
+ for (i = 0; i < 10; i++) {
+ for (;;) {
+ if (((ulint)p) % 4 == 0) {
+
+ if (*((ulint*)p) == MEM_BLOCK_MAGIC_N) {
+ fprintf(stderr,
+ "Mem block at - %lu, file %s, line %lu\n",
+ dist, p + sizeof(ulint),
+ *(ulint*)(p + 8 + sizeof(ulint)));
+
+ break;
+ }
+
+ if (*((ulint*)p) == MEM_FREED_BLOCK_MAGIC_N) {
+ fprintf(stderr,
+ "Freed mem block at - %lu, file %s, line %lu\n",
+ dist, p + sizeof(ulint),
+ *(ulint*)(p + 8 + sizeof(ulint)));
+
+ break;
+ }
+ }
+
+ p--;
+ dist++;
+ }
+
+ p--;
+ dist++;
+ }
+
+ fprintf(stderr,
+ "InnoDB: Scanning forward trying to find next allocated mem blocks\n");
+
+ p = ptr;
+ dist = 0;
+
+ for (i = 0; i < 10; i++) {
+ for (;;) {
+ if (((ulint)p) % 4 == 0) {
+
+ if (*((ulint*)p) == MEM_BLOCK_MAGIC_N) {
+ fprintf(stderr,
+ "Mem block at + %lu, file %s, line %lu\n",
+ dist, p + sizeof(ulint),
+ *(ulint*)(p + 8 + sizeof(ulint)));
+
+ break;
+ }
+
+ if (*((ulint*)p) == MEM_FREED_BLOCK_MAGIC_N) {
+ fprintf(stderr,
+ "Freed mem block at + %lu, file %s, line %lu\n",
+ dist, p + sizeof(ulint),
+ *(ulint*)(p + 8 + sizeof(ulint)));
+
+ break;
+ }
+ }
+
+ p++;
+ dist++;
+ }
+
+ p++;
+ dist++;
+ }
+}
diff --git a/innobase/mem/mem0mem.c b/innobase/mem/mem0mem.c
index 19a2c0d61a7..58fb618e2db 100644
--- a/innobase/mem/mem0mem.c
+++ b/innobase/mem/mem0mem.c
@@ -14,8 +14,9 @@ Created 6/9/1994 Heikki Tuuri
#include "mach0data.h"
#include "buf0buf.h"
-#include "mem0dbg.c"
#include "btr0sea.h"
+#include "srv0srv.h"
+#include "mem0dbg.c"
/*
THE MEMORY MANAGEMENT
@@ -85,18 +86,12 @@ mem_alloc_func_noninline(
/*=====================*/
/* out, own: free storage, NULL if did not
succeed */
- ulint n /* in: desired number of bytes */
- #ifdef UNIV_MEM_DEBUG
- ,char* file_name, /* in: file name where created */
+ ulint n, /* in: desired number of bytes */
+ char* file_name, /* in: file name where created */
ulint line /* in: line where created */
- #endif
)
{
- return(mem_alloc_func(n
-#ifdef UNIV_MEM_DEBUG
- , file_name, line
-#endif
- ));
+ return(mem_alloc_func(n, file_name, line));
}
/*******************************************************************
@@ -113,8 +108,10 @@ mem_heap_create_block(
if init_block is not NULL, its size in bytes */
void* init_block, /* in: init block in fast create, type must be
MEM_HEAP_DYNAMIC */
- ulint type) /* in: type of heap: MEM_HEAP_DYNAMIC, or
+ ulint type, /* in: type of heap: MEM_HEAP_DYNAMIC, or
MEM_HEAP_BUFFER possibly ORed to MEM_HEAP_BTR_SEARCH */
+ char* file_name,/* in: file name where created */
+ ulint line) /* in: line where created */
{
mem_block_t* block;
ulint len;
@@ -164,7 +161,11 @@ mem_heap_create_block(
}
block->magic_n = MEM_BLOCK_MAGIC_N;
-
+ ut_memcpy(&(block->file_name), file_name + ut_strlen(file_name) - 7,
+ 7);
+ block->file_name[7]='\0';
+ block->line = line;
+
mem_block_set_len(block, len);
mem_block_set_type(block, type);
mem_block_set_free(block, MEM_BLOCK_HEADER_SIZE);
@@ -223,8 +224,8 @@ mem_heap_add_block(
new_size = n;
}
- new_block = mem_heap_create_block(heap, new_size, NULL, heap->type);
-
+ new_block = mem_heap_create_block(heap, new_size, NULL, heap->type,
+ heap->file_name, heap->line);
if (new_block == NULL) {
return(NULL);
@@ -255,7 +256,8 @@ mem_heap_block_free(
type = heap->type;
len = block->len;
init_block = block->init_block;
-
+ block->magic_n = MEM_FREED_BLOCK_MAGIC_N;
+
#ifdef UNIV_MEM_DEBUG
/* In the debug version we set the memory to a random combination
of hex 0xDE and 0xAD. */