Merged revisions 104086 via svnmerge from
authorRussell Bryant <russell@russellbryant.com>
Mon, 25 Feb 2008 18:38:51 +0000 (18:38 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 25 Feb 2008 18:38:51 +0000 (18:38 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r104086 | russell | 2008-02-25 12:38:10 -0600 (Mon, 25 Feb 2008) | 4 lines

Ensure that the channel doesn't disappear in agent_logoff().  If it does, it
could cause a crash.
(fixes the crash reported in BE-396)

........

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

channels/chan_agent.c

index 2aeebf5..7fce983 100644 (file)
@@ -1513,10 +1513,29 @@ static int agent_logoff(const char *agent, int soft)
                        ret = 0;
                        if (p->owner || p->chan) {
                                if (!soft) {
-                                       if (p->owner)
+                                       ast_mutex_lock(&p->lock);
+
+                                       while (p->owner && ast_channel_trylock(p->owner)) {
+                                               ast_mutex_unlock(&p->lock);
+                                               usleep(1);
+                                               ast_mutex_lock(&p->lock);
+                                       }
+                                       if (p->owner) {
                                                ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
-                                       if (p->chan)
+                                               ast_channel_unlock(p->owner);
+                                       }
+
+                                       while (p->chan && ast_channel_trylock(p->chan)) {
+                                               ast_mutex_unlock(&p->lock);
+                                               usleep(1);
+                                               ast_mutex_lock(&p->lock);
+                                       }
+                                       if (p->chan) {
                                                ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
+                                               ast_channel_unlock(p->chan);
+                                       }
+
+                                       ast_mutex_unlock(&p->lock);
                                } else
                                        p->deferlogoff = 1;
                        } else {