diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-08-08 03:01:29 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-08-08 03:01:29 +0000 |
commit | 5a6bc4d4fea0fda6eab57a1d6f93833b911fd7f5 (patch) | |
tree | 778db8784daab048dcef321ca6c5f7fc1e721fed /channels/chan_local.c | |
parent | a849faaf4ea9d4e889063111a26613e3ec5c62d4 (diff) |
Properly defuse race in chan_local, fix extremely unlikely path for losing lock in chan_agent
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1276 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_local.c')
-rwxr-xr-x | channels/chan_local.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/channels/chan_local.c b/channels/chan_local.c index 7567c81e4..7267a8d1f 100755 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -71,11 +71,14 @@ static struct local_pvt { static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f) { - struct ast_channel *other; - if (isoutbound) + struct ast_channel *other, *us; + if (isoutbound) { + us = p->chan; other = p->owner; - else + } else { + us = p->owner; other = p->chan; + } if (!other) return 0; p->glaredetect = 1; @@ -90,8 +93,11 @@ retrylock: if (pthread_mutex_trylock(&other->lock)) { /* Failed to lock. Release main lock and try again */ ast_pthread_mutex_unlock(&p->lock); + ast_pthread_mutex_unlock(&us->lock); /* Wait just a bit */ usleep(1); + /* Only we can destroy ourselves, so we can't disappear here */ + ast_pthread_mutex_lock(&us->lock); ast_pthread_mutex_lock(&p->lock); goto retrylock; } |