Commit a7d9a38e authored by Sergei Golubchik's avatar Sergei Golubchik

dbug fix: only do safemalloc checks if a function is selected

mysqlslap: fix a crash when mysql_store_result() fails

client/mysqlslap.c:
  fix a crash
dbug/dbug.c:
  only do safemalloc checks if a function is selected
mysql-test/mysql-test-run.pl:
  it's easier to add new gdb parameters this way
storage/maria/ma_open.c:
  typo in a comment
parent 4ab4afde
...@@ -1886,10 +1886,17 @@ pthread_handler_t run_task(void *p) ...@@ -1886,10 +1886,17 @@ pthread_handler_t run_task(void *p)
{ {
if (mysql_field_count(mysql)) if (mysql_field_count(mysql))
{ {
result= mysql_store_result(mysql); if (result= mysql_store_result(mysql))
while ((row = mysql_fetch_row(result))) {
counter++; while ((row = mysql_fetch_row(result)))
mysql_free_result(result); counter++;
mysql_free_result(result);
}
else
{
fprintf(stderr,"%s: Error in mysql_store_result(): %d %s\n",
my_progname, mysql_errno(mysql), mysql_error(mysql));
}
} }
} while(mysql_next_result(mysql) == 0); } while(mysql_next_result(mysql) == 0);
queries++; queries++;
......
...@@ -177,7 +177,11 @@ ...@@ -177,7 +177,11 @@
static void perror(); /* Fake system/library error print routine */ static void perror(); /* Fake system/library error print routine */
#endif #endif
#ifdef SAFEMALLOC
IMPORT int _sanity(const char *file,uint line); /* safemalloc sanity checker */ IMPORT int _sanity(const char *file,uint line); /* safemalloc sanity checker */
#else
#define _sanity(X,Y) (1)
#endif
/* /*
* The user may specify a list of functions to trace or * The user may specify a list of functions to trace or
...@@ -287,7 +291,7 @@ static void PushState(CODE_STATE *cs); ...@@ -287,7 +291,7 @@ static void PushState(CODE_STATE *cs);
/* Free memory associated with debug state. */ /* Free memory associated with debug state. */
static void FreeState (CODE_STATE *cs, struct settings *state, int free_state); static void FreeState (CODE_STATE *cs, struct settings *state, int free_state);
/* Test for tracing enabled */ /* Test for tracing enabled */
static int DoTrace(CODE_STATE *cs, int tracing); static int DoTrace(CODE_STATE *cs);
/* /*
return values of DoTrace. return values of DoTrace.
Can also be used as bitmask: ret & DO_TRACE Can also be used as bitmask: ret & DO_TRACE
...@@ -726,7 +730,7 @@ void FixTraceFlags_helper(CODE_STATE *cs, const char *func, ...@@ -726,7 +730,7 @@ void FixTraceFlags_helper(CODE_STATE *cs, const char *func,
It's ok, because cs->framep may only affect DO_TRACE/DONT_TRACE return It's ok, because cs->framep may only affect DO_TRACE/DONT_TRACE return
values, but we ignore them here anyway values, but we ignore them here anyway
*/ */
switch(DoTrace(cs, 1)) { switch(DoTrace(cs)) {
case ENABLE_TRACE: case ENABLE_TRACE:
framep->level|= TRACE_ON; framep->level|= TRACE_ON;
break; break;
...@@ -1153,18 +1157,23 @@ void _db_enter_(const char *_func_, const char *_file_, ...@@ -1153,18 +1157,23 @@ void _db_enter_(const char *_func_, const char *_file_,
(void) fflush(cs->stack->prof_file); (void) fflush(cs->stack->prof_file);
} }
#endif #endif
switch (DoTrace(cs, TRACING)) { switch (DoTrace(cs)) {
case ENABLE_TRACE: case ENABLE_TRACE:
cs->framep->level|= TRACE_ON; cs->framep->level|= TRACE_ON;
if (!TRACING) break; if (!TRACING) break;
/* fall through */ /* fall through */
case DO_TRACE: case DO_TRACE:
if (!cs->locked) if ((cs->stack->flags & SANITY_CHECK_ON) && _sanity(_file_,_line_))
pthread_mutex_lock(&THR_LOCK_dbug); cs->stack->flags &= ~SANITY_CHECK_ON;
DoPrefix(cs, _line_); if (TRACING)
Indent(cs, cs->level); {
(void) fprintf(cs->stack->out_file, ">%s\n", cs->func); if (!cs->locked)
DbugFlush(cs); /* This does a unlock */ pthread_mutex_lock(&THR_LOCK_dbug);
DoPrefix(cs, _line_);
Indent(cs, cs->level);
(void) fprintf(cs->stack->out_file, ">%s\n", cs->func);
DbugFlush(cs); /* This does a unlock */
}
break; break;
case DISABLE_TRACE: case DISABLE_TRACE:
cs->framep->level&= ~TRACE_ON; cs->framep->level&= ~TRACE_ON;
...@@ -1172,11 +1181,6 @@ void _db_enter_(const char *_func_, const char *_file_, ...@@ -1172,11 +1181,6 @@ void _db_enter_(const char *_func_, const char *_file_,
case DONT_TRACE: case DONT_TRACE:
break; break;
} }
#ifdef SAFEMALLOC
if (cs->stack->flags & SANITY_CHECK_ON)
if (_sanity(_file_,_line_)) /* Check of safemalloc */
cs->stack->flags &= ~SANITY_CHECK_ON;
#endif
errno=save_errno; errno=save_errno;
} }
...@@ -1218,25 +1222,24 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_) ...@@ -1218,25 +1222,24 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_)
} }
else else
{ {
#ifdef SAFEMALLOC
if (cs->stack->flags & SANITY_CHECK_ON)
{
if (_sanity(_stack_frame_->file,_line_))
cs->stack->flags &= ~SANITY_CHECK_ON;
}
#endif
#ifndef THREAD #ifndef THREAD
if (DoProfile(cs)) if (DoProfile(cs))
(void) fprintf(cs->stack->prof_file, PROF_XFMT, Clock(), cs->func); (void) fprintf(cs->stack->prof_file, PROF_XFMT, Clock(), cs->func);
#endif #endif
if (TRACING && DoTrace(cs, 1) & DO_TRACE) if (DoTrace(cs) & DO_TRACE)
{ {
if (!cs->locked) if ((cs->stack->flags & SANITY_CHECK_ON) &&
pthread_mutex_lock(&THR_LOCK_dbug); _sanity(_stack_frame_->file,_line_))
DoPrefix(cs, _line_); cs->stack->flags &= ~SANITY_CHECK_ON;
Indent(cs, cs->level); if (TRACING)
(void) fprintf(cs->stack->out_file, "<%s\n", cs->func); {
DbugFlush(cs); if (!cs->locked)
pthread_mutex_lock(&THR_LOCK_dbug);
DoPrefix(cs, _line_);
Indent(cs, cs->level);
(void) fprintf(cs->stack->out_file, "<%s\n", cs->func);
DbugFlush(cs);
}
} }
} }
/* /*
...@@ -1694,28 +1697,24 @@ void _db_end_() ...@@ -1694,28 +1697,24 @@ void _db_end_()
* *
* DoTrace check to see if tracing is current enabled * DoTrace check to see if tracing is current enabled
* *
* tracing is the value of TRACING to check if the tracing is enabled
* or 1 to check if the function is enabled (in _db_keyword_)
*
* DESCRIPTION * DESCRIPTION
* *
* Checks to see if tracing is enabled based on whether the * Checks to see if dbug in this function is enabled based on
* user has specified tracing, the maximum trace depth has * whether the maximum trace depth has been reached, the current
* not yet been reached, the current function is selected, * function is selected, and the current process is selected.
* and the current process is selected.
* *
*/ */
static int DoTrace(CODE_STATE *cs, int tracing) static int DoTrace(CODE_STATE *cs)
{ {
if ((cs->stack->maxdepth == 0 || cs->level <= cs->stack->maxdepth) && if ((cs->stack->maxdepth == 0 || cs->level <= cs->stack->maxdepth) &&
InList(cs->stack->processes, cs->process) & (MATCHED|INCLUDE)) InList(cs->stack->processes, cs->process) & (MATCHED|INCLUDE))
switch(InList(cs->stack->functions, cs->func)) { switch(InList(cs->stack->functions, cs->func)) {
case INCLUDE|SUBDIR: return ENABLE_TRACE; case INCLUDE|SUBDIR: return ENABLE_TRACE;
case INCLUDE: return tracing ? DO_TRACE : DONT_TRACE; case INCLUDE: return DO_TRACE;
case MATCHED|SUBDIR: case MATCHED|SUBDIR:
case NOT_MATCHED|SUBDIR: case NOT_MATCHED|SUBDIR:
case MATCHED: return tracing && framep_trace_flag(cs, cs->framep) ? case MATCHED: return framep_trace_flag(cs, cs->framep) ?
DO_TRACE : DONT_TRACE; DO_TRACE : DONT_TRACE;
case EXCLUDE: case EXCLUDE:
case NOT_MATCHED: return DONT_TRACE; case NOT_MATCHED: return DONT_TRACE;
...@@ -1786,7 +1785,7 @@ BOOLEAN _db_keyword_(CODE_STATE *cs, const char *keyword, int strict) ...@@ -1786,7 +1785,7 @@ BOOLEAN _db_keyword_(CODE_STATE *cs, const char *keyword, int strict)
get_code_state_if_not_set_or_return FALSE; get_code_state_if_not_set_or_return FALSE;
strict=strict ? INCLUDE : INCLUDE|MATCHED; strict=strict ? INCLUDE : INCLUDE|MATCHED;
return DEBUGGING && DoTrace(cs, 1) & DO_TRACE && return DEBUGGING && DoTrace(cs) & DO_TRACE &&
InList(cs->stack->keywords, keyword) & strict; InList(cs->stack->keywords, keyword) & strict;
} }
......
...@@ -5109,8 +5109,9 @@ sub gdb_arguments { ...@@ -5109,8 +5109,9 @@ sub gdb_arguments {
else else
{ {
# write init file for mysqld # write init file for mysqld
mtr_tofile($gdb_init_file, mtr_tofile($gdb_init_file, <<EOGDB );
"set args $str\n"); set args $str
EOGDB
} }
if ( $opt_manual_gdb ) if ( $opt_manual_gdb )
......
...@@ -809,7 +809,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) ...@@ -809,7 +809,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags)
if (!(share->state_history= (MARIA_STATE_HISTORY *) if (!(share->state_history= (MARIA_STATE_HISTORY *)
my_malloc(sizeof(*share->state_history), MYF(MY_WME)))) my_malloc(sizeof(*share->state_history), MYF(MY_WME))))
goto err; goto err;
share->state_history->trid= 0; /* Visibly by all */ share->state_history->trid= 0; /* Visible by all */
share->state_history->state= share->state.state; share->state_history->state= share->state.state;
share->state_history->next= 0; share->state_history->next= 0;
} }
......
...@@ -455,6 +455,7 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit) ...@@ -455,6 +455,7 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit)
trnman_active_transactions--; trnman_active_transactions--;
pthread_mutex_unlock(&LOCK_trn_list); pthread_mutex_unlock(&LOCK_trn_list);
DBUG_ASSERT(trn->short_id);
/* the rest is done outside of a critical section */ /* the rest is done outside of a critical section */
my_atomic_rwlock_rdlock(&LOCK_short_trid_to_trn); my_atomic_rwlock_rdlock(&LOCK_short_trid_to_trn);
......
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