Be sure to hold lock during answer
authorMark Spencer <markster@digium.com>
Wed, 23 Jun 2004 17:41:51 +0000 (17:41 +0000)
committerMark Spencer <markster@digium.com>
Wed, 23 Jun 2004 17:41:51 +0000 (17:41 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3286 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channel.c
channels/chan_sip.c

index 89ebcbb..dd2b814 100755 (executable)
--- a/channel.c
+++ b/channel.c
@@ -750,16 +750,17 @@ void ast_channel_unregister(char *type)
 int ast_answer(struct ast_channel *chan)
 {
        int res = 0;
+       ast_mutex_lock(&chan->lock);
        /* Stop if we're a zombie or need a soft hangup */
-       if (chan->zombie || ast_check_hangup(chan)) 
+       if (chan->zombie || ast_check_hangup(chan)) {
+               ast_mutex_unlock(&chan->lock);
                return -1;
+       }
        switch(chan->_state) {
        case AST_STATE_RINGING:
        case AST_STATE_RING:
-               ast_mutex_lock(&chan->lock);
                if (chan->pvt->answer)
                        res = chan->pvt->answer(chan);
-               ast_mutex_unlock(&chan->lock);
                ast_setstate(chan, AST_STATE_UP);
                if (chan->cdr)
                        ast_cdr_answer(chan->cdr);
@@ -770,6 +771,7 @@ int ast_answer(struct ast_channel *chan)
                        ast_cdr_answer(chan->cdr);
                break;
        }
+       ast_mutex_unlock(&chan->lock);
        return 0;
 }
 
index ddb4d8a..805c571 100755 (executable)
@@ -1597,7 +1597,7 @@ static int sip_answer(struct ast_channel *ast)
        char *codec;
        struct sip_pvt *p = ast->pvt->pvt;
 
-       
+       ast_mutex_lock(&p->lock);
        if (ast->_state != AST_STATE_UP) {
        
        
@@ -1616,6 +1616,7 @@ static int sip_answer(struct ast_channel *ast)
                        ast_log(LOG_DEBUG, "sip_answer(%s)\n", ast->name);
                res = transmit_response_with_sdp(p, "200 OK", &p->initreq, 1);
        }
+       ast_mutex_unlock(&p->lock);
        return res;
 }