Commit e42130e9 authored by Monty's avatar Monty Committed by Sergei Golubchik

Fixes that enables my_new.cc (new wrapper using my_malloc)

This is not enabled by default, as there are leaks in the
server that needs to be fixed first. One can compile
with -DUSE_MYSYS_NEW to find the memory leaks from
'new'. More comments can be found in mysys/my_new.cc
parent a93c5145
......@@ -362,7 +362,8 @@ ENDIF()
# Run platform tests
INCLUDE(configure.cmake)
# force -DUSE_MYSYS_NEW unless already done by HAVE_CXX_NEW
# Use mysys/my_new.cc if '#include <new>' doesn't work.
# One can also specify -DUSE_MYSYS_NEW explicitly, see mysys/my_new.cc
IF(NOT HAVE_CXX_NEW)
ADD_DEFINITIONS(-DUSE_MYSYS_NEW)
ENDIF()
......
......@@ -25,34 +25,55 @@
#include "mysys_priv.h"
#include <new>
#ifdef USE_MYSYS_NEW
/*
We don't yet enable the my new operators by default.
The reasons (for MariaDB) are:
- There are several global objects in plugins (wsrep_info, InnoDB,
tpool) that allocates data with 'new'. These objects are not
freed properly before exit() is called and safemalloc will report
these as lost memory. The proper fix is to ensure that all plugins
either ensure that all objects frees there data or the global object are
changed to a pointer that as allocated and freed on demand.
Doing this will make it easier to find leaks and also speed up plugin
loads when we don't have to initialize a lot of objects until they
are really needed.
- Rocksdb calls malloc_usable_size, that will crash if used with new based
on my_malloc. One suggested fix would be to not define
ROCKSDB_MALLOC_USABLE_SIZE if MYSYS_USE_NEW is defined.
When the above is fixed, we can add enable ADD_DEFINITIONS(-DUSE_MYSYS_NEW)
in CMakeLists.txt
*/
#if defined(USE_MYSYS_NEW)
void *operator new (size_t sz)
{
return (void *) my_malloc (sz ? sz : 1, MYF(0));
return (void *) my_malloc(key_memory_new, sz ? sz : 1, MYF(0));
}
void *operator new[] (size_t sz)
{
return (void *) my_malloc (sz ? sz : 1, MYF(0));
return (void *) my_malloc(key_memory_new, sz ? sz : 1, MYF(0));
}
void* operator new(std::size_t sz, const std::nothrow_t&) throw()
{
return (void *) my_malloc (sz ? sz : 1, MYF(0));
return (void *) my_malloc(key_memory_new, sz ? sz : 1, MYF(0));
}
void* operator new[](std::size_t sz, const std::nothrow_t&) throw()
{
return (void *) my_malloc (sz ? sz : 1, MYF(0));
return (void *) my_malloc(key_memory_new, sz ? sz : 1, MYF(0));
}
void operator delete (void *ptr, std::size_t)
void operator delete (void *ptr, std::size_t) throw ()
{
my_free(ptr);
}
void operator delete (void *ptr)
void operator delete (void *ptr) throw ()
{
my_free(ptr);
}
......
......@@ -48,6 +48,7 @@ PSI_memory_key key_memory_my_err_head;
PSI_memory_key key_memory_my_file_info;
PSI_memory_key key_memory_pack_frm;
PSI_memory_key key_memory_charsets;
PSI_memory_key key_memory_new= PSI_INSTRUMENT_MEM;
#ifdef _WIN32
PSI_memory_key key_memory_win_SECURITY_ATTRIBUTES;
......
......@@ -88,6 +88,7 @@ extern PSI_memory_key key_memory_my_err_head;
extern PSI_memory_key key_memory_my_file_info;
extern PSI_memory_key key_memory_pack_frm;
extern PSI_memory_key key_memory_charsets;
extern PSI_memory_key key_memory_new;
#ifdef _WIN32
extern PSI_memory_key key_memory_win_SECURITY_ATTRIBUTES;
......
......@@ -39,8 +39,12 @@ static pthread_mutex_t sf_mutex;
static int init_done= 0;
#ifndef SF_REMEMBER_FRAMES
#ifdef USE_MYSYS_NEW
#define SF_REMEMBER_FRAMES 14
#else
#define SF_REMEMBER_FRAMES 8
#endif
#endif /* USE_MYSYS_NEW */
#endif /* SF_REMEMBER_FRAMES */
/* ignore the first two frames (sf_malloc itself, and my_malloc) */
#define SF_FRAMES_SKIP 2
......
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