Fix deadlock potential with ast_set_hangupsource() calls.
[asterisk/asterisk.git] / channels / chan_dahdi.c
index e6c39d2..6c5b00e 100644 (file)
@@ -8955,13 +8955,18 @@ static struct ast_frame *__dahdi_exception(struct ast_channel *ast)
                f = &p->subs[idx].f;
                return f;
        }
+
        f = dahdi_handle_event(ast);
+       if (!f) {
+               const char *name = ast_strdupa(ast_channel_name(ast));
 
-       /* tell the cdr this zap device hung up */
-       if (f == NULL) {
-               ast_set_hangupsource(ast, ast_channel_name(ast), 0);
+               /* Tell the CDR this DAHDI device hung up */
+               ast_mutex_unlock(&p->lock);
+               ast_channel_unlock(ast);
+               ast_set_hangupsource(ast, name, 0);
+               ast_channel_lock(ast);
+               ast_mutex_lock(&p->lock);
        }
-
        return f;
 }