From 139e8afc2c165a08f4fa13da70b0aad3cf7b9df5 Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 22 Dec 2017 14:16:21 +0200 Subject: [PATCH] Re-enable 'S' for --debug (sf_sanity checking for each call) - Fixed also a wrong comment and a wrong argument to printf --- dbug/dbug.c | 16 +++++++++++++--- include/my_dbug.h | 1 + include/my_sys.h | 1 + mysys/my_init.c | 4 ++++ mysys/my_malloc.c | 2 -- mysys/safemalloc.c | 4 ++-- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/dbug/dbug.c b/dbug/dbug.c index e4125a3efea..dedc455147b 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -128,7 +128,6 @@ #define SANITY_CHECK_ON (1U << 12) /* Check memory on every DBUG_ENTER/RETURN */ #define TRACE_ON (1U << 31) /* Trace enabled. MUST be the highest bit!*/ -#define sf_sanity() (0) #define TRACING (cs->stack->flags & TRACE_ON) #define DEBUGGING (cs->stack->flags & DEBUG_ON) @@ -272,6 +271,11 @@ static void PushState(CODE_STATE *cs); static void FreeState (CODE_STATE *cs, int free_state); /* Test for tracing enabled */ static int DoTrace(CODE_STATE *cs); +static int default_my_dbug_sanity(void); + +int (*dbug_sanity)(void)= default_my_dbug_sanity; + + /* return values of DoTrace. Can also be used as bitmask: ret & DO_TRACE @@ -1121,7 +1125,7 @@ void _db_enter_(const char *_func_, const char *_file_, if (!TRACING) break; /* fall through */ case DO_TRACE: - if ((cs->stack->flags & SANITY_CHECK_ON) && sf_sanity()) + if ((cs->stack->flags & SANITY_CHECK_ON) && (*dbug_sanity)()) cs->stack->flags &= ~SANITY_CHECK_ON; if (TRACING) { @@ -1190,7 +1194,7 @@ void _db_return_(struct _db_stack_frame_ *_stack_frame_) if (DoTrace(cs) & DO_TRACE) { int org_cs_locked; - if ((cs->stack->flags & SANITY_CHECK_ON) && sf_sanity()) + if ((cs->stack->flags & SANITY_CHECK_ON) && (*dbug_sanity)()) cs->stack->flags &= ~SANITY_CHECK_ON; if (TRACING) { @@ -2248,6 +2252,12 @@ const char* _db_get_func_(void) return cs->func; } + +static int default_my_dbug_sanity(void) +{ + return 0; +} + #else /* diff --git a/include/my_dbug.h b/include/my_dbug.h index b9194428f18..d93c86141d6 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -63,6 +63,7 @@ extern void _db_flush_(void); extern void dbug_swap_code_state(void **code_state_store); extern void dbug_free_code_state(void **code_state_store); extern const char* _db_get_func_(void); +extern int (*dbug_sanity)(void); #define DBUG_LEAVE do { \ _db_stack_frame_.line= __LINE__; \ diff --git a/include/my_sys.h b/include/my_sys.h index 2f31bbaea8a..58d87eae72c 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -157,6 +157,7 @@ char *guess_malloc_library(); /* If we have our own safemalloc (for debugging) */ #if defined(SAFEMALLOC) void sf_report_leaked_memory(my_thread_id id); +int sf_sanity(); extern my_thread_id (*sf_malloc_dbug_id)(void); #define SAFEMALLOC_REPORT_MEMORY(X) sf_report_leaked_memory(X) #else diff --git a/mysys/my_init.c b/mysys/my_init.c index 7db0a58d471..9bd1185a3bf 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -105,6 +105,10 @@ my_bool my_init(void) if (my_thread_global_init()) return 1; +#if defined(SAFEMALLOC) && !defined(DBUG_OFF) + dbug_sanity= sf_sanity; +#endif + /* $HOME is needed early to parse configuration files located in ~/ */ if ((home_dir= getenv("HOME")) != 0) home_dir= intern_filename(home_dir_buff, home_dir); diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c index dc02d3896bd..2b022522f67 100644 --- a/mysys/my_malloc.c +++ b/mysys/my_malloc.c @@ -200,8 +200,6 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags) /** Free memory allocated with my_malloc. - @remark Relies on free being able to handle a NULL argument. - @param ptr Pointer to the memory allocated by my_malloc. */ void my_free(void *ptr) diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c index b8d9442fbc9..ae8993fbf00 100644 --- a/mysys/safemalloc.c +++ b/mysys/safemalloc.c @@ -330,7 +330,7 @@ static int bad_ptr(const char *where, void *ptr) magicend[3] != MAGICEND3) { DBUG_PRINT("error",("Overrun buffer %p", ptr)); - warn("Error: %s overrun buffer %p", where); + warn("Error: %s overrun buffer %p", where, ptr); fprintf(stderr, "Allocated at "); print_stack(irem->frame); return 1; @@ -340,7 +340,7 @@ static int bad_ptr(const char *where, void *ptr) } /* check all allocated memory list for consistency */ -static int sf_sanity() +int sf_sanity() { struct st_irem *irem; int flag= 0;