diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-02 21:36:39 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-02 21:36:39 +0000 |
commit | e08cb0ffa6dbd44c975ad5186f326ba2ee94b718 (patch) | |
tree | 1ff96db0aa1cf867ac85b9adfc65844e982bbde7 /channels | |
parent | 4015a6816f3f78a0f4ef60529029d4a7dcbb1c9a (diff) |
Have the DEADLOCK_AVOIDANCE macro warn when an unlock fails, to help catch potentially large software bugs.
(closes issue #17407)
Reported by: pdf
Patches:
20100527__issue17407.diff.txt uploaded by tilghman (license 14)
Review: https://reviewboard.asterisk.org/r/751/
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@273793 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_agent.c | 7 | ||||
-rw-r--r-- | channels/chan_dahdi.c | 6 | ||||
-rw-r--r-- | channels/chan_h323.c | 6 | ||||
-rw-r--r-- | channels/chan_local.c | 12 |
4 files changed, 23 insertions, 8 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 7bbee404a..bd1988118 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -707,7 +707,12 @@ static int agent_indicate(struct ast_channel *ast, int condition, const void *da ast_mutex_lock(&p->lock); if (p->chan && !ast_check_hangup(p->chan)) { while (ast_channel_trylock(p->chan)) { - ast_channel_unlock(ast); + int res; + if ((res = ast_channel_unlock(ast))) { + ast_log(LOG_ERROR, "chan_agent bug! Channel was not locked upon entry to agent_indicate: %s\n", strerror(res)); + ast_mutex_unlock(&p->lock); + return -1; + } usleep(1); ast_channel_lock(ast); } diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index e9cf2db4d..e47b56107 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -4399,8 +4399,12 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast) /* Here we have to retain the lock on both the main channel, the 3-way channel, and the private structure -- not especially easy or clean */ while (p->subs[SUB_THREEWAY].owner && ast_mutex_trylock(&p->subs[SUB_THREEWAY].owner->lock)) { + int res; /* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */ - ast_mutex_unlock(&p->lock); + if ((res = ast_mutex_unlock(&p->lock))) { + ast_log(LOG_ERROR, "chan_dahdi bug! '&p->lock' was not locked upon entry to 'dahdi_handle_dtmfup': %s\n", strerror(res)); + return NULL; + } DEADLOCK_AVOIDANCE(&ast->lock); /* We can grab ast and p in that order, without worry. We should make sure nothing seriously bad has happened though like some sort of bizarre double diff --git a/channels/chan_h323.c b/channels/chan_h323.c index 6d0718698..edb19ef43 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -313,10 +313,8 @@ static int oh323_simulate_dtmf_end(const void *data) if (pvt) { ast_mutex_lock(&pvt->lock); /* Don't hold pvt lock while trying to lock the channel */ - while(pvt->owner && ast_channel_trylock(pvt->owner)) { - ast_mutex_unlock(&pvt->lock); - usleep(1); - ast_mutex_lock(&pvt->lock); + while (pvt->owner && ast_channel_trylock(pvt->owner)) { + DEADLOCK_AVOIDANCE(&pvt->lock); } if (pvt->owner) { diff --git a/channels/chan_local.c b/channels/chan_local.c index e705ee582..81f16eadf 100644 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -183,10 +183,18 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra /* Ensure that we have both channels locked */ while (other && ast_channel_trylock(other)) { - ast_mutex_unlock(&p->lock); + int res; + if ((res = ast_mutex_unlock(&p->lock))) { + ast_log(LOG_ERROR, "chan_local bug! '&p->lock' was not locked when entering local_queue_frame! (%s)\n", strerror(res)); + return -1; + } if (us && us_locked) { do { - ast_channel_unlock(us); + if (ast_channel_unlock(us)) { + ast_log(LOG_ERROR, "chan_local bug! Our channel was not locked, yet arguments indicated that it was!!\n"); + ast_mutex_lock(&p->lock); + return -1; + } usleep(1); ast_channel_lock(us); } while (ast_mutex_trylock(&p->lock)); |