Fix crash during CDR update.

The ast_cdr_setcid() and ast_cdr_update() were shown in ASTERISK-18836 to
be called by different threads for the same channel.  The channel driver
thread and the PBX thread running dialplan.

* Add lock protection around CDR API calls that access an ast_channel
pointer.

(closes issue ASTERISK-18836)
Reported by: gpluser

Review: https://reviewboard.asterisk.org/r/1628/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@348362 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2011-12-16 20:55:17 +00:00
parent 6b17e5e23c
commit 74da7648bb
9 changed files with 109 additions and 30 deletions

View File

@@ -478,10 +478,12 @@ static void clear_caller(struct findme_user *tmpuser)
if (tmpuser && tmpuser->ochan && tmpuser->state >= 0) {
outbound = tmpuser->ochan;
ast_channel_lock(outbound);
if (!outbound->cdr) {
outbound->cdr = ast_cdr_alloc();
if (outbound->cdr)
if (outbound->cdr) {
ast_cdr_init(outbound->cdr, outbound);
}
}
if (outbound->cdr) {
char tmp[256];
@@ -492,11 +494,15 @@ static void clear_caller(struct findme_user *tmpuser)
ast_cdr_start(outbound->cdr);
ast_cdr_end(outbound->cdr);
/* If the cause wasn't handled properly */
if (ast_cdr_disposition(outbound->cdr, outbound->hangupcause))
if (ast_cdr_disposition(outbound->cdr, outbound->hangupcause)) {
ast_cdr_failed(outbound->cdr);
} else
}
} else {
ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
ast_hangup(tmpuser->ochan);
}
ast_channel_unlock(outbound);
ast_hangup(outbound);
tmpuser->ochan = NULL;
}
}
@@ -876,6 +882,7 @@ static void findmeexec(struct fm_args *tpargs)
AST_LIST_INSERT_TAIL(findme_user_list, tmpuser, entry);
} else {
ast_verb(3, "couldn't reach at this number.\n");
ast_channel_lock(outbound);
if (!outbound->cdr) {
outbound->cdr = ast_cdr_alloc();
}
@@ -895,6 +902,7 @@ static void findmeexec(struct fm_args *tpargs)
} else {
ast_log(LOG_ERROR, "Unable to create Call Detail Record\n");
}
ast_channel_unlock(outbound);
ast_hangup(outbound);
ast_free(tmpuser);
}