]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix deadlock potential with some ast_indicate/ast_indicate_data calls.
authorRichard Mudgett <rmudgett@digium.com>
Wed, 14 Mar 2012 22:28:35 +0000 (22:28 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Wed, 14 Mar 2012 22:28:35 +0000 (22:28 +0000)
Calling ast_indicate()/ast_indicate_data() with the channel lock held can
result in a deadlock with a local channel because of how local channels
need to avoid deadlock.
........

Merged revisions 359451 from http://svn.asterisk.org/svn/asterisk/branches/1.8

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@359453 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_agent.c
include/asterisk/channel.h
main/channel.c

index f0c047b6808ec988ea1d284df95dc0e78fe96818..979cbba344d98434be923f155e44f0302e1fadf1 100644 (file)
@@ -967,9 +967,7 @@ static int agent_hangup(struct ast_channel *ast)
                p->chan->_bridge = NULL;
                /* If they're dead, go ahead and hang up on the agent now */
                if (p->dead) {
-                       ast_channel_lock(p->chan);
                        ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
-                       ast_channel_unlock(p->chan);
                } else if (p->loginstart) {
                        indicate_chan = ast_channel_ref(p->chan);
                        tmp_moh = ast_strdupa(p->moh);
@@ -978,11 +976,9 @@ static int agent_hangup(struct ast_channel *ast)
        ast_mutex_unlock(&p->lock);
 
        if (indicate_chan) {
-               ast_channel_lock(indicate_chan);
                ast_indicate_data(indicate_chan, AST_CONTROL_HOLD,
                        S_OR(tmp_moh, NULL),
                        !ast_strlen_zero(tmp_moh) ? strlen(tmp_moh) + 1 : 0);
-               ast_channel_unlock(indicate_chan);
                indicate_chan = ast_channel_unref(indicate_chan);
        }
 
index 72249f7d14e00f1238a70861bb6cb65e8d59dbcf..8a371a11f3c03ba6d455f51d250463adc3cb4bbf 100644 (file)
@@ -1635,6 +1635,7 @@ int ast_call(struct ast_channel *chan, char *addr, int timeout);
 
 /*!
  * \brief Indicates condition of channel
+ * \note Absolutely _NO_ channel locks should be held before calling this function.
  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
  * \param chan channel to change the indication
  * \param condition which condition to indicate on the channel
@@ -1644,6 +1645,7 @@ int ast_indicate(struct ast_channel *chan, int condition);
 
 /*!
  * \brief Indicates condition of channel, with payload
+ * \note Absolutely _NO_ channel locks should be held before calling this function.
  * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
  * \param chan channel to change the indication
  * \param condition which condition to indicate on the channel
index 3193cf50243263031d30aa050adb15c8ae214ef4..370ce50c095b2df4d34263a8b594805f0b0a5d36 100644 (file)
@@ -4029,12 +4029,14 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
                                                ast_party_connected_line_free(&connected);
                                                break;
                                        }
+                                       ast_channel_unlock(chan);
                                        if (ast_channel_connected_line_macro(NULL, chan, &connected, 1, 0)) {
                                                ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE,
                                                        read_action_payload->payload,
                                                        read_action_payload->payload_size);
                                        }
                                        ast_party_connected_line_free(&connected);
+                                       ast_channel_lock(chan);
                                        break;
                                }
                                ast_frfree(f);
@@ -9592,10 +9594,16 @@ int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struc
        }
        ast_channel_unlock(macro_chan);
 
-       if (!(retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args))) {
+       retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
+       if (!retval) {
+               struct ast_party_connected_line saved_connected;
+
+               ast_party_connected_line_init(&saved_connected);
                ast_channel_lock(macro_chan);
-               ast_channel_update_connected_line(macro_chan, &macro_chan->connected, NULL);
+               ast_party_connected_line_copy(&saved_connected, &macro_chan->connected);
                ast_channel_unlock(macro_chan);
+               ast_channel_update_connected_line(macro_chan, &saved_connected, NULL);
+               ast_party_connected_line_free(&saved_connected);
        }
 
        return retval;
@@ -9633,9 +9641,14 @@ int ast_channel_redirecting_macro(struct ast_channel *autoservice_chan, struct a
 
        retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
        if (!retval) {
+               struct ast_party_redirecting saved_redirecting;
+
+               ast_party_redirecting_init(&saved_redirecting);
                ast_channel_lock(macro_chan);
-               ast_channel_update_redirecting(macro_chan, &macro_chan->redirecting, NULL);
+               ast_party_redirecting_copy(&saved_redirecting, &macro_chan->redirecting);
                ast_channel_unlock(macro_chan);
+               ast_channel_update_redirecting(macro_chan, &saved_redirecting, NULL);
+               ast_party_redirecting_free(&saved_redirecting);
        }
 
        return retval;