[Asterisk-code-review] rtp engine.c: Fix deadlock potential copying RTP payload maps. (asterisk[13])
Richard Mudgett
asteriskteam at digium.com
Sat Apr 29 18:14:49 CDT 2017
Richard Mudgett has uploaded a new change for review. ( https://gerrit.asterisk.org/5561 )
Change subject: rtp_engine.c: Fix deadlock potential copying RTP payload maps.
......................................................................
rtp_engine.c: Fix deadlock potential copying RTP payload maps.
There is a theoretical potential to deadlock in
ast_rtp_codecs_payloads_copy() because it locks two different
ast_rtp_codecs locks. It is theoretical because the callers of the
function are either copying between a local ast_rtp_codecs struct and a
RTP instance of the ast_rtp_codecs struct. Or they are copying between
the caller and callee channel RTP instances before initiating the call to
the callee. Neither of these situations could actually result in a
deadlock because there cannot be another thread involved at the time.
* Add deadlock avoidance code to ast_rtp_codecs_payloads_copy() since it
locks two ast_rtp_codecs locks to perform a copy.
This only affects v13 since this deadlock avoidance code is already in
newer branches.
Change-Id: I1aa0b168f94049bd59bbd74a85bd1e78718f09e5
---
M main/rtp_engine.c
1 file changed, 8 insertions(+), 2 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/5561/1
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index f1da873..3377087 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -708,8 +708,14 @@
{
int i;
- ast_rwlock_rdlock(&src->codecs_lock);
ast_rwlock_wrlock(&dest->codecs_lock);
+
+ /* Deadlock avoidance because of held write lock. */
+ while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
+ ast_rwlock_unlock(&dest->codecs_lock);
+ sched_yield();
+ ast_rwlock_wrlock(&dest->codecs_lock);
+ }
for (i = 0; i < AST_VECTOR_SIZE(&src->payloads); i++) {
struct ast_rtp_payload_type *type;
@@ -732,8 +738,8 @@
}
}
dest->framing = src->framing;
- ast_rwlock_unlock(&dest->codecs_lock);
ast_rwlock_unlock(&src->codecs_lock);
+ ast_rwlock_unlock(&dest->codecs_lock);
}
void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
--
To view, visit https://gerrit.asterisk.org/5561
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1aa0b168f94049bd59bbd74a85bd1e78718f09e5
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
More information about the asterisk-code-review
mailing list