Fix inability to shutdown gracefully due to an unending channel reference.
[asterisk/asterisk.git] / main / message.c
index 1ac9231..26fea1a 100644 (file)
@@ -756,7 +756,18 @@ static void chan_cleanup(struct ast_channel *chan)
        ast_channel_unlock(chan);
 }
 
-AST_THREADSTORAGE(msg_q_chan);
+static void destroy_msg_q_chan(void *data)
+{
+       struct ast_channel **chan = data;
+
+       if (!*chan) {
+               return;
+       }
+
+       ast_channel_release(*chan);
+}
+
+AST_THREADSTORAGE_CUSTOM(msg_q_chan, NULL, destroy_msg_q_chan);
 
 /*!
  * \internal
@@ -1318,3 +1329,8 @@ int ast_msg_init(void)
 
        return res;
 }
+
+void ast_msg_shutdown(void)
+{
+       msg_q_tp = ast_taskprocessor_unreference(msg_q_tp);
+}