From 6e3fdcffa6cbcbf54102c4784b82bf919650a81e Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Fri, 25 Apr 2003 04:57:11 +0000 Subject: [PATCH] Fix potential call feature race git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@911 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_zap.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/channels/chan_zap.c b/channels/chan_zap.c index 3dc7a83ca7..a3eb6eb116 100755 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -2925,6 +2925,9 @@ struct ast_frame *zt_exception(struct ast_channel *ast) int res; int usedindex=-1; int index; + struct ast_frame *f; + + ast_pthread_mutex_lock(&p->lock); index = zt_get_index(ast, p, 1); @@ -3001,15 +3004,21 @@ struct ast_frame *zt_exception(struct ast_channel *ast) default: ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", event2str(res)); } - return &p->subs[index].f; + f = &p->subs[index].f; + ast_pthread_mutex_unlock(&p->lock); + return f; } if (!p->radio) ast_log(LOG_DEBUG, "Exception on %d, channel %d\n", ast->fds[0],p->channel); /* If it's not us, return NULL immediately */ if (ast != p->owner) { ast_log(LOG_WARNING, "We're %s, not %s\n", ast->name, p->owner->name); - return &p->subs[index].f; + f = &p->subs[index].f; + ast_pthread_mutex_unlock(&p->lock); + return f; } - return zt_handle_event(ast); + f = zt_handle_event(ast); + ast_pthread_mutex_unlock(&p->lock); + return f; } struct ast_frame *zt_read(struct ast_channel *ast) @@ -3133,8 +3142,9 @@ struct ast_frame *zt_read(struct ast_channel *ast) } if (res != (p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE)) { ast_log(LOG_DEBUG, "Short read (%d/%d), must be an event...\n", res, p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE); + f = zt_handle_event(ast); pthread_mutex_unlock(&p->lock); - return zt_handle_event(ast); + return f; } if (p->tdd) { /* if in TDD mode, see if we receive that */ int c;