summaryrefslogtreecommitdiff
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2009-06-08 17:32:04 +0000
committerMark Michelson <mmichelson@digium.com>2009-06-08 17:32:04 +0000
commit5965e276a78ec827f8d624789ecd7b0133773466 (patch)
tree14e07624fa0bde38a2a7f61115c4f37e1d00b726 /channels/chan_sip.c
parent17fd9651fb3b87ebb743a1c1ccd739d2252afd2b (diff)
Fix a deadlock that could occur when setting rtp stats on SIP calls.
(closes issue #15143) Reported by: cristiandimache Patches: 15143.patch uploaded by mmichelson (license 60) Tested by: cristiandimache git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@199588 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r--channels/chan_sip.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index c079e5900..b5ac173ba 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -5933,6 +5933,17 @@ static int sip_hangup(struct ast_channel *ast)
struct ast_channel *bridge = ast_bridged_channel(oldowner);
char quality_buf[AST_MAX_USER_FIELD], *quality;
+ /* We need to get the lock on bridge because ast_rtp_instance_set_stats_vars will attempt
+ * to lock the bridge. This may get hairy...
+ */
+ while (bridge && ast_channel_trylock(bridge)) {
+ sip_pvt_unlock(p);
+ do {
+ CHANNEL_DEADLOCK_AVOIDANCE(oldowner);
+ } while (sip_pvt_trylock(p));
+ bridge = ast_bridged_channel(oldowner);
+ }
+
if (p->rtp) {
ast_rtp_instance_set_stats_vars(oldowner, p->rtp);
}
@@ -5943,6 +5954,7 @@ static int sip_hangup(struct ast_channel *ast)
if (IS_SIP_TECH(bridge->tech) && q && q->rtp) {
ast_rtp_instance_set_stats_vars(bridge, q->rtp);
}
+ ast_channel_unlock(bridge);
}
if (p->do_history || oldowner) {
@@ -21061,7 +21073,22 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req)
/* Get RTCP quality before end of call */
if (p->do_history || p->owner) {
char quality_buf[AST_MAX_USER_FIELD], *quality;
- struct ast_channel *bridge = p->owner ? ast_bridged_channel(p->owner) : NULL;
+ struct ast_channel *bridge = p->owner ? ast_bridged_channel(p->owner) : NULL;
+
+ /* We need to get the lock on bridge because ast_rtp_instance_set_stats_vars will attempt
+ * to lock the bridge. This may get hairy...
+ */
+ while (bridge && ast_channel_trylock(bridge)) {
+ ast_channel_unlock(p->owner);
+ do {
+ /* Can't use DEADLOCK_AVOIDANCE since p is an ao2 object */
+ sip_pvt_unlock(p);
+ usleep(1);
+ sip_pvt_lock(p);
+ } while (p->owner && ast_channel_trylock(p->owner));
+ bridge = p->owner ? ast_bridged_channel(p->owner) : NULL;
+ }
+
if (p->rtp && (quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
if (p->do_history) {
@@ -21090,6 +21117,7 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req)
if (IS_SIP_TECH(bridge->tech) && q && q->rtp) {
ast_rtp_instance_set_stats_vars(bridge, q->rtp);
}
+ ast_channel_unlock(bridge);
}
if (p->vrtp && (quality = ast_rtp_instance_get_quality(p->vrtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {