Merge "stasis: Allow filtering by formatter"
[asterisk/asterisk.git] / funcs / func_dialgroup.c
index 4a789d6..9a98b3c 100644 (file)
@@ -31,8 +31,6 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include <sys/stat.h>
 
 #include "asterisk/module.h"
@@ -144,7 +142,7 @@ static int dialgroup_read(struct ast_channel *chan, const char *cmd, char *data,
 
        buf[0] = '\0';
 
-       i = ao2_iterator_init(grhead->entries, OBJ_POINTER);
+       i = ao2_iterator_init(grhead->entries, 0);
        while ((entry = ao2_iterator_next(&i))) {
                int tmp = strlen(entry->name);
                /* Ensure that we copy only complete names, not partials */
@@ -165,6 +163,7 @@ static int dialgroup_read(struct ast_channel *chan, const char *cmd, char *data,
                ao2_ref(entry, -1);
        }
        ao2_iterator_destroy(&i);
+       ao2_ref(grhead, -1);
 
        return res;
 }
@@ -173,11 +172,17 @@ static int dialgroup_refreshdb(struct ast_channel *chan, const char *cdialgroup)
 {
        int len = 500, res = 0;
        char *buf = NULL;
+       char *new_buf;
        char *dialgroup = ast_strdupa(cdialgroup);
 
        do {
                len *= 2;
-               buf = ast_realloc(buf, len);
+               new_buf = ast_realloc(buf, len);
+               if (!new_buf) {
+                       ast_free(buf);
+                       return -1;
+               }
+               buf = new_buf;
 
                if ((res = dialgroup_read(chan, "", dialgroup, buf, len)) < 0) {
                        ast_free(buf);
@@ -216,7 +221,8 @@ static int dialgroup_write(struct ast_channel *chan, const char *cmd, char *data
                grhead = ao2_alloc(sizeof(*grhead), group_destroy);
                if (!grhead)
                        return -1;
-               grhead->entries = ao2_container_alloc(37, entry_hash_fn, entry_cmp_fn);
+               grhead->entries = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+                       entry_hash_fn, NULL, entry_cmp_fn);
                if (!grhead->entries) {
                        ao2_ref(grhead, -1);
                        return -1;
@@ -231,7 +237,9 @@ static int dialgroup_write(struct ast_channel *chan, const char *cmd, char *data
 
                /* Remove all existing */
                ao2_ref(grhead->entries, -1);
-               if (!(grhead->entries = ao2_container_alloc(37, entry_hash_fn, entry_cmp_fn))) {
+               grhead->entries = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+                       entry_hash_fn, NULL, entry_cmp_fn);
+               if (!grhead->entries) {
                        ao2_unlink(group_container, grhead);
                        ao2_ref(grhead, -1);
                        return -1;
@@ -292,7 +300,9 @@ static int load_module(void)
        struct ast_db_entry *dbtree, *tmp;
        char groupname[AST_MAX_EXTENSION], *ptr;
 
-       if ((group_container = ao2_container_alloc(37, group_hash_fn, group_cmp_fn))) {
+       group_container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+               group_hash_fn, NULL, group_cmp_fn);
+       if (group_container) {
                /* Refresh groups from astdb */
                if ((dbtree = ast_db_gettree("dialgroup", NULL))) {
                        for (tmp = dbtree; tmp; tmp = tmp->next) {