Merged revisions 317584 via svnmerge from
[asterisk/asterisk.git] / apps / app_queue.c
index e494c7e..8b1072e 100644 (file)
@@ -4566,6 +4566,17 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
        if (need_weight)
                ao2_unlock(queues);
        lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT), forwardsallowed, update_connectedline);
+       /* The ast_channel_datastore_remove() function could fail here if the
+        * datastore was moved to another channel during a masquerade. If this is
+        * the case, don't free the datastore here because later, when the channel
+        * to which the datastore was moved hangs up, it will attempt to free this
+        * datastore again, causing a crash
+        */
+       ast_channel_lock(qe->chan);
+       if (datastore && !ast_channel_datastore_remove(qe->chan, datastore)) {
+               ast_datastore_free(datastore);
+       }
+       ast_channel_unlock(qe->chan);
        ao2_lock(qe->parent);
        if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY || qe->parent->strategy == QUEUE_STRATEGY_RRORDERED) {
                store_next_rr(qe, outgoing);