Convert a few places to use ast_calloc_with_stringfields where applicable.
authorSean Bright <sean@malleable.com>
Fri, 15 Jan 2010 18:21:50 +0000 (18:21 +0000)
committerSean Bright <sean@malleable.com>
Fri, 15 Jan 2010 18:21:50 +0000 (18:21 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@240368 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_jack.c
apps/app_meetme.c
cdr/cdr_tds.c
cel/cel_tds.c
channels/chan_sip.c
main/features.c
main/manager.c
main/pbx.c
res/res_phoneprov.c
res/res_smdi.c

index e8f717b..2f263b6 100644 (file)
@@ -676,11 +676,7 @@ static struct jack_data *jack_data_alloc(void)
 {
        struct jack_data *jack_data;
 
 {
        struct jack_data *jack_data;
 
-       if (!(jack_data = ast_calloc(1, sizeof(*jack_data))))
-               return NULL;
-
-       if (ast_string_field_init(jack_data, 32)) {
-               ast_free(jack_data);
+       if (!(jack_data = ast_calloc_with_stringfields(1, struct jack_data, 32))) {
                return NULL;
        }
 
                return NULL;
        }
 
index d340ae1..17fec5f 100644 (file)
@@ -6166,10 +6166,7 @@ static int sla_build_trunk(struct ast_config *cfg, const char *cat)
                return -1;
        }
 
                return -1;
        }
 
-       if (!(trunk = ast_calloc(1, sizeof(*trunk))))
-               return -1;
-       if (ast_string_field_init(trunk, 32)) {
-               ast_free(trunk);
+       if (!(trunk = ast_calloc_with_stringfields(1, struct sla_trunk, 32))) {
                return -1;
        }
 
                return -1;
        }
 
@@ -6295,10 +6292,7 @@ static int sla_build_station(struct ast_config *cfg, const char *cat)
                return -1;
        }
 
                return -1;
        }
 
-       if (!(station = ast_calloc(1, sizeof(*station))))
-               return -1;
-       if (ast_string_field_init(station, 32)) {
-               ast_free(station);
+       if (!(station = ast_calloc_with_stringfields(1, struct sla_station, 32))) {
                return -1;
        }
 
                return -1;
        }
 
index 17c569a..a9a5d5c 100644 (file)
@@ -538,13 +538,9 @@ static int load_module(void)
        dberrhandle(tds_error_handler);
        dbmsghandle(tds_message_handler);
 
        dberrhandle(tds_error_handler);
        dbmsghandle(tds_message_handler);
 
-       settings = ast_calloc(1, sizeof(*settings));
+       settings = ast_calloc_with_stringfields(1, struct cdr_tds_config, 256);
 
 
-       if (!settings || ast_string_field_init(settings, 256)) {
-               if (settings) {
-                       ast_free(settings);
-                       settings = NULL;
-               }
+       if (!settings) {
                dbexit();
                return AST_MODULE_LOAD_DECLINE;
        }
                dbexit();
                return AST_MODULE_LOAD_DECLINE;
        }
index 138a9cd..631c3cb 100644 (file)
@@ -541,13 +541,9 @@ static int load_module(void)
        dberrhandle(tds_error_handler);
        dbmsghandle(tds_message_handler);
 
        dberrhandle(tds_error_handler);
        dbmsghandle(tds_message_handler);
 
-       settings = ast_calloc(1, sizeof(*settings));
+       settings = ast_calloc_with_stringfields(1, struct cel_tds_config, 256);
 
 
-       if (!settings || ast_string_field_init(settings, 256)) {
-               if (settings) {
-                       ast_free(settings);
-                       settings = NULL;
-               }
+       if (!settings) {
                dbexit();
                return AST_MODULE_LOAD_DECLINE;
        }
                dbexit();
                return AST_MODULE_LOAD_DECLINE;
        }
index a3a8420..a013937 100644 (file)
@@ -7859,17 +7859,11 @@ static int sip_register(const char *value, int lineno)
                }
        }
 
                }
        }
 
-       if (!(reg = ast_calloc(1, sizeof(*reg)))) {
+       if (!(reg = ast_calloc_with_stringfields(1, struct sip_registry, 256))) {
                ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n");
                return -1;
        }
 
                ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n");
                return -1;
        }
 
-       if (ast_string_field_init(reg, 256)) {
-               ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry strings\n");
-               ast_free(reg);
-               return -1;
-       }
-
        ast_atomic_fetchadd_int(&regobjs, 1);
        ASTOBJ_INIT(reg);
        ast_string_field_set(reg, callback, ast_strip_quoted(S_OR(host2.extension, "s"), "\"", "\""));
        ast_atomic_fetchadd_int(&regobjs, 1);
        ASTOBJ_INIT(reg);
        ast_string_field_set(reg, callback, ast_strip_quoted(S_OR(host2.extension, "s"), "\"", "\""));
@@ -7935,12 +7929,7 @@ static int sip_subscribe_mwi(const char *value, int lineno)
                }
        }
        
                }
        }
        
-       if (!(mwi = ast_calloc(1, sizeof(*mwi)))) {
-               return -1;
-       }
-       
-       if (ast_string_field_init(mwi, 256)) {
-               ast_free(mwi);
+       if (!(mwi = ast_calloc_with_stringfields(1, struct sip_subscription_mwi, 256))) {
                return -1;
        }
        
                return -1;
        }
        
index 8ba1955..68f2f85 100644 (file)
@@ -1940,14 +1940,9 @@ static struct feature_group* register_group(const char *fgname)
                return NULL;
        }
 
                return NULL;
        }
 
-       if (!(fg = ast_calloc(1, sizeof(*fg))))
+       if (!(fg = ast_calloc_with_stringfields(1, struct feature_group, 128)))
                return NULL;
 
                return NULL;
 
-       if (ast_string_field_init(fg, 128)) {
-               ast_free(fg);
-               return NULL;
-       }
-
        ast_string_field_set(fg, gname, fgname);
 
        AST_LIST_INSERT_HEAD(&feature_groups, fg, entry);
        ast_string_field_set(fg, gname, fgname);
 
        AST_LIST_INSERT_HEAD(&feature_groups, fg, entry);
@@ -1980,14 +1975,9 @@ static void register_group_feature(struct feature_group *fg, const char *exten,
                return;
        }
 
                return;
        }
 
-       if (!(fge = ast_calloc(1, sizeof(*fge))))
+       if (!(fge = ast_calloc_with_stringfields(1, struct feature_group_exten, 128)))
                return;
 
                return;
 
-       if (ast_string_field_init(fge, 128)) {
-               ast_free(fge);
-               return;
-       }
-
        ast_string_field_set(fge, exten, S_OR(exten, feature->exten));
 
        fge->feature = feature;
        ast_string_field_set(fge, exten, S_OR(exten, feature->exten));
 
        fge->feature = feature;
index e7cf931..3af61b3 100644 (file)
@@ -4430,12 +4430,7 @@ int ast_manager_register2(const char *action, int auth, int (*func)(struct manse
        char *tmpxml;
 #endif
 
        char *tmpxml;
 #endif
 
-       if (!(cur = ast_calloc(1, sizeof(*cur)))) {
-               return -1;
-       }
-
-       if (ast_string_field_init(cur, 128)) {
-               ast_free(cur);
+       if (!(cur = ast_calloc_with_stringfields(1, struct manager_action, 128))) {
                return -1;
        }
 
                return -1;
        }
 
index b9ba3fb..520e336 100644 (file)
@@ -3114,13 +3114,7 @@ int pbx_builtin_raise_exception(struct ast_channel *chan, const char *reason)
                ds = ast_datastore_alloc(&exception_store_info, NULL);
                if (!ds)
                        return -1;
                ds = ast_datastore_alloc(&exception_store_info, NULL);
                if (!ds)
                        return -1;
-               exception = ast_calloc(1, sizeof(struct pbx_exception));
-               if (!exception) {
-                       ast_datastore_free(ds);
-                       return -1;
-               }
-               if (ast_string_field_init(exception, 128)) {
-                       ast_free(exception);
+               if (!(exception = ast_calloc_with_stringfields(1, struct pbx_exception, 128))) {
                        ast_datastore_free(ds);
                        return -1;
                }
                        ast_datastore_free(ds);
                        return -1;
                }
index 49fdbf8..ff3046b 100644 (file)
@@ -636,12 +636,7 @@ static void build_profile(const char *name, struct ast_variable *v)
                                AST_APP_ARG(mimetype);
                        );
 
                                AST_APP_ARG(mimetype);
                        );
 
-                       if (!(pp_file = ast_calloc(1, sizeof(*pp_file)))) {
-                               profile = unref_profile(profile);
-                               return;
-                       }
-                       if (ast_string_field_init(pp_file, 32)) {
-                               ast_free(pp_file);
+                       if (!(pp_file = ast_calloc_with_stringfields(1, struct phoneprov_file, 32))) {
                                profile = unref_profile(profile);
                                return;
                        }
                                profile = unref_profile(profile);
                                return;
                        }
@@ -712,13 +707,7 @@ static struct extension *build_extension(struct ast_config *cfg, const char *nam
        const char *tmp;
        int i;
 
        const char *tmp;
        int i;
 
-       if (!(exten = ast_calloc(1, sizeof(*exten)))) {
-               return NULL;
-       }
-
-       if (ast_string_field_init(exten, 32)) {
-               ast_free(exten);
-               exten = NULL;
+       if (!(exten = ast_calloc_with_stringfields(1, struct extension, 32))) {
                return NULL;
        }
 
                return NULL;
        }
 
index 3cb7fa3..c59bd4a 100644 (file)
@@ -848,13 +848,8 @@ static void append_mailbox_mapping(struct ast_variable *var, struct ast_smdi_int
        struct mailbox_mapping *mm;
        char *mailbox, *context;
 
        struct mailbox_mapping *mm;
        char *mailbox, *context;
 
-       if (!(mm = ast_calloc(1, sizeof(*mm))))
+       if (!(mm = ast_calloc_with_stringfields(1, struct mailbox_mapping, 32)))
                return;
                return;
-       
-       if (ast_string_field_init(mm, 32)) {
-               free(mm);
-               return;
-       }
 
        ast_string_field_set(mm, smdi, var->name);
 
 
        ast_string_field_set(mm, smdi, var->name);