maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #01699
[Branch ~maria-captains/maria/5.1] Rev 2781: Protect stack->keywords with THR_LOCK_dbug
------------------------------------------------------------
revno: 2781
committer: Michael Widenius <monty@xxxxxxxxxxxx>
branch nick: maria-5.1
timestamp: Mon 2009-12-07 02:52:40 +0200
message:
Protect stack->keywords with THR_LOCK_dbug
This solves a core dump in MariaDB when one sets the GLOBAL.DEBUG variable in mysql-test-run when other threads are checking the keyword list
modified:
dbug/dbug.c
--
lp:maria
https://code.launchpad.net/~maria-captains/maria/5.1
Your team Maria developers is subscribed to branch lp:maria.
To unsubscribe from this branch go to https://code.launchpad.net/~maria-captains/maria/5.1/+edit-subscription.
=== modified file 'dbug/dbug.c'
--- dbug/dbug.c 2009-09-07 20:50:10 +0000
+++ dbug/dbug.c 2009-12-07 00:52:40 +0000
@@ -497,12 +497,18 @@
const char *end;
int rel, f_used=0;
struct settings *stack;
+ int org_cs_locked;
stack= cs->stack;
+ if (!(org_cs_locked= cs->locked))
+ {
+ cs->locked= 1;
+ pthread_mutex_lock(&THR_LOCK_dbug);
+ }
+
if (control[0] == '-' && control[1] == '#')
control+=2;
-
rel= control[0] == '+' || control[0] == '-';
if ((!rel || (!stack->out_file && !stack->next)))
{
@@ -550,9 +556,11 @@
while (control < end)
{
int c, sign= (*control == '+') ? 1 : (*control == '-') ? -1 : 0;
- if (sign) control++;
+ if (sign)
+ control++;
c= *control++;
- if (*control == ',') control++;
+ if (*control == ',')
+ control++;
/* XXX when adding new cases here, don't forget _db_explain_ ! */
switch (c) {
case 'd':
@@ -570,7 +578,7 @@
{
if (DEBUGGING)
stack->keywords= ListDel(stack->keywords, control, end);
- break;
+ break;
}
stack->keywords= ListAdd(stack->keywords, control, end);
stack->flags |= DEBUG_ON;
@@ -718,8 +726,13 @@
control=end+1;
end= DbugStrTok(control);
}
- return !rel || f_used;
-}
+ if (!org_cs_locked)
+ {
+ pthread_mutex_unlock(&THR_LOCK_dbug);
+ cs->locked= 0;
+ }
+ return !rel || f_used;}
+
#define framep_trace_flag(cs, frp) (frp ? \
frp->level & TRACE_ON : \
@@ -1340,11 +1353,11 @@
va_start(args,format);
+ if (!cs->locked)
+ pthread_mutex_lock(&THR_LOCK_dbug);
if (_db_keyword_(cs, cs->u_keyword, 0))
{
int save_errno=errno;
- if (!cs->locked)
- pthread_mutex_lock(&THR_LOCK_dbug);
DoPrefix(cs, cs->u_line);
if (TRACING)
Indent(cs, cs->level + 1);
@@ -1356,6 +1369,9 @@
DbugFlush(cs);
errno=save_errno;
}
+ else if (!cs->locked)
+ pthread_mutex_unlock(&THR_LOCK_dbug);
+
va_end(args);
}
@@ -1386,10 +1402,10 @@
CODE_STATE *cs;
get_code_state_or_return;
+ if (!cs->locked)
+ pthread_mutex_lock(&THR_LOCK_dbug);
if (_db_keyword_(cs, keyword, 0))
{
- if (!cs->locked)
- pthread_mutex_lock(&THR_LOCK_dbug);
DoPrefix(cs, _line_);
if (TRACING)
{
@@ -1420,6 +1436,8 @@
(void) fputc('\n',cs->stack->out_file);
DbugFlush(cs);
}
+ else if (!cs->locked)
+ pthread_mutex_unlock(&THR_LOCK_dbug);
}
@@ -2105,7 +2123,8 @@
{
if (fp != stderr && fp != stdout && fclose(fp) == EOF)
{
- pthread_mutex_lock(&THR_LOCK_dbug);
+ if (!cs->locked)
+ pthread_mutex_lock(&THR_LOCK_dbug);
(void) fprintf(cs->stack->out_file, ERR_CLOSE, cs->process);
perror("");
DbugFlush(cs);