Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 149683) +++ apps/app_queue.c (working copy) @@ -1481,7 +1481,6 @@ /* Delete if unused (else will be deleted when last caller leaves). */ ao2_unlink(queues, q); ao2_unlock(q); - queue_unref(q); } return NULL; } @@ -1976,8 +1975,6 @@ if (q->dead) { /* It's dead and nobody is in it, so kill it */ ao2_unlink(queues, q); - /* unref the container's reference to the queue */ - queue_unref(q); } /* unref the explicit ref earlier in the function */ queue_unref(q); @@ -2032,11 +2029,10 @@ } } ao2_unlock(q); + queue_unref(q); if (found) { - queue_unref(q); break; } - queue_unref(q); } return found; } @@ -3913,6 +3909,8 @@ if (!mem->dynamic) { ao2_ref(mem, -1); ao2_unlock(q); + queue_unref(q); + ao2_unlock(queues); return RES_NOT_DYNAMIC; } q->membercount--; @@ -5451,13 +5449,15 @@ } } - queue_iter = ao2_iterator_init(queues, 0); + queue_iter = ao2_iterator_init(queues, F_AO2I_DONTLOCK); + ao2_lock(queues); while ((q = ao2_iterator_next(&queue_iter))) { float sl; ao2_lock(q); if (argc == 3 && strcasecmp(q->name, argv[2])) { ao2_unlock(q); + queue_unref(q); continue; } found = 1; @@ -5528,6 +5528,7 @@ } queue_unref(q); /* Unref the iterator's reference */ } + ao2_unlock(queues); if (!found) { if (argc == 3) ast_str_set(&out, 0, "No such queue: %s.", argv[2]);