diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-02-25 18:38:10 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-02-25 18:38:10 +0000 |
commit | 2c9e764508bd70c6c1430422e0e8dc4eae163022 (patch) | |
tree | 457f29a0de6bb78f7aa60b800c122f2ce53fc7bd /channels | |
parent | eb7b5070af9380b2ff503706a59bd12ac0ac7b6a (diff) |
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: http://svn.digium.com/svn/asterisk/branches/1.4@104086 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_agent.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 789461bea..3a5e8a2b3 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -1581,10 +1581,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 { |