Skip to content

Commit

Permalink
Re-enable 'S' for --debug (sf_sanity checking for each call)
Browse files Browse the repository at this point in the history
- Fixed also a wrong comment and a wrong argument to printf
  • Loading branch information
montywi committed Dec 22, 2017
1 parent 1464f48 commit 139e8af
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
16 changes: 13 additions & 3 deletions dbug/dbug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -2248,6 +2252,12 @@ const char* _db_get_func_(void)
return cs->func;
}


static int default_my_dbug_sanity(void)
{
return 0;
}

#else

/*
Expand Down
1 change: 1 addition & 0 deletions include/my_dbug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__; \
Expand Down
1 change: 1 addition & 0 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions mysys/my_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions mysys/my_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mysys/safemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 139e8af

Please sign in to comment.