Commit 5beb816a authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Make it possible to compile without SAFEMALLOC in debug builds

Default to no SAFEMALLOC on Windows, because C runtime malloc
has this functionslity already
parent 5d67eb6b
......@@ -17,6 +17,17 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/dbug
${CMAKE_SOURCE_DIR}/include
)
IF(WIN32)
SET(DEFAULT_SAFEMALLOC OFF)
ELSE()
SET(DEFAULT_SAFEMALLOC ON)
ENDIF()
OPTION(WITH_SAFEMALLOC ${DEFAULT_SAFEMALLOC} "Use safemalloc for debug builds. Will result in slower execution.")
IF(WITH_SAFEMALLOC)
ADD_DEFINITIONS( -DSAFEMALLOC)
ENDIF()
SET(DBUG_SOURCES dbug.c)
ADD_CONVENIENCE_LIBRARY(dbug ${DBUG_SOURCES})
TARGET_LINK_LIBRARIES(dbug mysys)
......
......@@ -2253,6 +2253,9 @@ static void free_memory(void *ptr);
void *_db_malloc_(size_t size)
{
#ifndef SAFEMALLOC
return malloc(size);
#else
CODE_STATE *cs= code_state();
struct st_irem *irem;
uchar *data;
......@@ -2318,10 +2321,14 @@ void *_db_malloc_(size_t size)
TRASH_ALLOC(data, size);
return data;
#endif
}
void *_db_realloc_(void *ptr, size_t size)
{
#ifndef SAFEMALLOC
return realloc(ptr, size);
#else
char *data;
if (!ptr)
......@@ -2338,15 +2345,19 @@ void *_db_realloc_(void *ptr, size_t size)
free_memory(ptr);
}
return data;
#endif
}
void _db_free_(void *ptr)
{
#ifndef SAFEMALLOC
free(ptr);
#else
if (!ptr || bad_ptr("Freeing", ptr))
return;
free_memory(ptr);
return;
#endif
}
static void free_memory(void *ptr)
......
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