All pastes #38050 Raw Edit

Mine

public text v1 · immutable
#38050 ·published 2006-01-22 18:46 UTC
rendered paste body
Index: apps/app_queue.c
===================================================================
--- apps/app_queue.c    (revision 8441)
+++ apps/app_queue.c    (working copy)
@@ -787,7 +787,34 @@
        }
 }

+static void free_members(struct ast_call_queue *q, int all)
+{
+       /* Free non-dynamic members */
+       struct member *curm, *next, *prev;

+       curm = q->members;
+       prev = NULL;
+       while(curm) {
+               next = curm->next;
+               if (all || !curm->dynamic) {
+                       if (prev)
+                               prev->next = next;
+                       else
+                               q->members = next;
+                       free(curm);
+               } else
+                       prev = curm;
+               curm = next;
+       }
+}
+
+static void destroy_queue(struct ast_call_queue *q)
+{
+       free_members(q, 1);
+       ast_mutex_destroy(&q->lock);
+       free(q);
+}
+
 /*!\brief Reload a single queue via realtime.
    \return Return the queue, or NULL if it doesn't exist.
    \note Should be called with the global qlock locked. */
@@ -838,7 +865,7 @@
                                /* Delete. */
                                AST_LIST_REMOVE(&queues, q, list);
                                ast_mutex_unlock(&q->lock);
-                               free(q);
+                               destroy_queue(q);
                        } else
                                ast_mutex_unlock(&q->lock);
                }
@@ -1022,37 +1049,6 @@
        return res;
 }

-static void free_members(struct ast_call_queue *q, int all)
-{
-       /* Free non-dynamic members */
-       struct member *curm, *next, *prev;
-
-       curm = q->members;
-       prev = NULL;
-       while(curm) {
-               next = curm->next;
-               if (all || !curm->dynamic) {
-                       if (prev)
-                               prev->next = next;
-                       else
-                               q->members = next;
-                       free(curm);
-               } else
-                       prev = curm;
-               curm = next;
-       }
-}
-
-static void destroy_queue(struct ast_call_queue *q)
-{
-       AST_LIST_LOCK(&queues);
-       AST_LIST_REMOVE(&queues, q, list);
-       AST_LIST_UNLOCK(&queues);
-       free_members(q, 1);
-       ast_mutex_destroy(&q->lock);
-       free(q);
-}
-
 static int play_file(struct ast_channel *chan, char *filename)
 {
        int res;
@@ -1260,6 +1256,9 @@
        ast_mutex_unlock(&q->lock);
        if (q->dead && !q->count) {
                /* It's dead and nobody is in it, so kill it */
+               AST_LIST_LOCK(&queues);
+               AST_LIST_REMOVE(&queues, q, list);
+               AST_LIST_UNLOCK(&queues);
                destroy_queue(q);
        }
 }
@@ -3371,10 +3370,10 @@
        AST_LIST_TRAVERSE_SAFE_BEGIN(&queues, q, list) {
                if (q->dead) {
                        AST_LIST_REMOVE_CURRENT(&queues, list);
-                       if (!q->count) {
-                               free(q);
-                       } else
-                               ast_log(LOG_WARNING, "XXX Leaking a little memory :( XXX\n");
+                       if (!q->count)
+                               destroy_queue(q);
+                       /* else
+                               ast_log(LOG_WARNING, "XXX Leaking a little memory :( XXX\n"); ??? */
                } else {
                        for (cur = q->members; cur; cur = cur->next)
                                cur->status = ast_device_state(cur->interface);