Commit f4cccb1f authored by marko's avatar marko

branches/zip: Map ut_malloc(), ut_realloc(), ut_free() to

malloc(), realloc(), free() when innodb_use_sys_malloc is set.

ut_free_all_mem(): If innodb_use_sys_malloc is set, do nothing,
because then ut_mem_block_list_inited will never be set.

log_init(): Use mem_alloc() instead of ut_malloc(), so that the
memory will be freed.  (Tested with Valgrind, although it is not
clear why the memory would be freed.)

rb://86 approved by Heikki Tuuri and Ken Jacobs.  This addresses Issue #168.
parent 51bc19d7
...@@ -739,7 +739,7 @@ log_init(void) ...@@ -739,7 +739,7 @@ log_init(void)
ut_a(LOG_BUFFER_SIZE >= 16 * OS_FILE_LOG_BLOCK_SIZE); ut_a(LOG_BUFFER_SIZE >= 16 * OS_FILE_LOG_BLOCK_SIZE);
ut_a(LOG_BUFFER_SIZE >= 4 * UNIV_PAGE_SIZE); ut_a(LOG_BUFFER_SIZE >= 4 * UNIV_PAGE_SIZE);
buf = ut_malloc(LOG_BUFFER_SIZE + OS_FILE_LOG_BLOCK_SIZE); buf = mem_alloc(LOG_BUFFER_SIZE + OS_FILE_LOG_BLOCK_SIZE);
log_sys->buf = ut_align(buf, OS_FILE_LOG_BLOCK_SIZE); log_sys->buf = ut_align(buf, OS_FILE_LOG_BLOCK_SIZE);
log_sys->buf_size = LOG_BUFFER_SIZE; log_sys->buf_size = LOG_BUFFER_SIZE;
......
...@@ -15,6 +15,7 @@ Created 5/11/1994 Heikki Tuuri ...@@ -15,6 +15,7 @@ Created 5/11/1994 Heikki Tuuri
#include "mem0mem.h" #include "mem0mem.h"
#include "os0sync.h" #include "os0sync.h"
#include "os0thread.h" #include "os0thread.h"
#include "srv0srv.h"
/* This struct is placed first in every allocated memory block */ /* This struct is placed first in every allocated memory block */
typedef struct ut_mem_block_struct ut_mem_block_t; typedef struct ut_mem_block_struct ut_mem_block_t;
...@@ -68,14 +69,29 @@ ut_malloc_low( ...@@ -68,14 +69,29 @@ ut_malloc_low(
ibool assert_on_error)/* in: if TRUE, we crash mysqld if the ibool assert_on_error)/* in: if TRUE, we crash mysqld if the
memory cannot be allocated */ memory cannot be allocated */
{ {
ulint retry_count = 0; ulint retry_count;
void* ret; void* ret;
if (srv_use_sys_malloc) {
ret = malloc(n);
ut_a(ret || !assert_on_error);
#ifdef UNIV_SET_MEM_TO_ZERO
if (set_to_zero) {
memset(ret, '\0', n);
UNIV_MEM_ALLOC(ret, n);
}
#endif
return(ret);
}
ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */ ut_ad((sizeof(ut_mem_block_t) % 8) == 0); /* check alignment ok */
if (!ut_mem_block_list_inited) { if (UNIV_UNLIKELY(!ut_mem_block_list_inited)) {
ut_mem_block_list_init(); ut_mem_block_list_init();
} }
retry_count = 0;
retry: retry:
os_fast_mutex_lock(&ut_list_mutex); os_fast_mutex_lock(&ut_list_mutex);
...@@ -239,6 +255,11 @@ ut_free( ...@@ -239,6 +255,11 @@ ut_free(
{ {
ut_mem_block_t* block; ut_mem_block_t* block;
if (srv_use_sys_malloc) {
free(ptr);
return;
}
block = (ut_mem_block_t*)((byte*)ptr - sizeof(ut_mem_block_t)); block = (ut_mem_block_t*)((byte*)ptr - sizeof(ut_mem_block_t));
os_fast_mutex_lock(&ut_list_mutex); os_fast_mutex_lock(&ut_list_mutex);
...@@ -291,6 +312,10 @@ ut_realloc( ...@@ -291,6 +312,10 @@ ut_realloc(
ulint min_size; ulint min_size;
void* new_ptr; void* new_ptr;
if (srv_use_sys_malloc) {
return(realloc(ptr, size));
}
if (ptr == NULL) { if (ptr == NULL) {
return(ut_malloc(size)); return(ut_malloc(size));
...@@ -338,6 +363,11 @@ ut_free_all_mem(void) ...@@ -338,6 +363,11 @@ ut_free_all_mem(void)
{ {
ut_mem_block_t* block; ut_mem_block_t* block;
if (!ut_mem_block_list_inited) {
return;
}
ut_mem_block_list_inited = FALSE;
os_fast_mutex_free(&ut_list_mutex); os_fast_mutex_free(&ut_list_mutex);
while ((block = UT_LIST_GET_FIRST(ut_mem_block_list))) { while ((block = UT_LIST_GET_FIRST(ut_mem_block_list))) {
......
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