diff -ur asterisk-1.0.3.bak/channel.c asterisk/channel.c --- asterisk-1.0.3.bak/channel.c 2004-12-15 17:45:21.000000000 -0500 +++ asterisk/channel.c 2004-12-15 17:51:26.000000000 -0500 @@ -373,13 +373,27 @@ struct ast_frame *prev, *cur; int blah = 1; int qlen = 0; + int retries = 0; + /* Build us a copy and free the original one */ f = ast_frdup(fin); if (!f) { ast_log(LOG_WARNING, "Unable to duplicate frame\n"); return -1; } - ast_mutex_lock(&chan->lock); + +retry: + if (ast_mutex_trylock(&chan->lock)) { + if (retries < 100) { + usleep(1); + retries++; + goto retry; + } else { + ast_log(LOG_WARNING, "Avoided deadlock on channel %s, %d retries",chan->name,retries); + return -1; + } + } + prev = NULL; cur = chan->pvt->readq; while(cur) { diff -ur asterisk-1.0.3.bak/channels/chan_h323.c asterisk/channels/chan_h323.c --- asterisk-1.0.3.bak/channels/chan_h323.c 2004-12-15 17:45:21.000000000 -0500 +++ asterisk/channels/chan_h323.c 2004-12-15 17:51:48.000000000 -0500 @@ -580,6 +580,12 @@ /* Retrieve audio/etc from channel. Assumes p->lock is already held. */ struct ast_frame *f; static struct ast_frame null_frame = { AST_FRAME_NULL, }; + static struct ast_frame hangup_frame = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; + + if (!p->rtp) { + ast_log(LOG_WARNING,"request to read rtp after rtp was destroyed"); + return &hangup_frame; + } /* Only apply it for the first packet, we just need the correct ip/port */ if(p->nat)