aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_musiconhold.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-01-21 22:09:06 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-01-21 22:09:06 +0000
commit1e6b875c67de180e41374795555dde2859e23783 (patch)
treee352cdb4d3acb3dfdb89cf9a9ff83c30fe90ff94 /res/res_musiconhold.c
parentffcb98861ad5f7e0f3b246e264e61e2fa991522d (diff)
- conversions to allocation wrappers
- replace malloc/memset with ast_calloc - replace malloc/ast_copy_string with ast_strdup (based on patch from issue #6299) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@8410 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_musiconhold.c')
-rw-r--r--res/res_musiconhold.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index ffbd41713..7ab065a5c 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -279,18 +279,17 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params)
{
struct moh_files_state *state;
struct mohclass *class = params;
- int allocated = 0;
- if (!chan->music_state && (state = malloc(sizeof(struct moh_files_state)))) {
+ if (!chan->music_state && (state = ast_calloc(1, sizeof(*state)))) {
chan->music_state = state;
- allocated = 1;
+ state->class = class;
} else
state = chan->music_state;
if (state) {
- if (allocated || state->class != class) {
+ if (state->class != class) {
/* initialize */
- memset(state, 0, sizeof(struct moh_files_state));
+ memset(state, 0, sizeof(*state));
state->class = class;
}
@@ -611,11 +610,9 @@ static struct mohclass *get_mohbyname(char *name)
static struct mohdata *mohalloc(struct mohclass *cl)
{
struct mohdata *moh;
- long flags;
- moh = malloc(sizeof(struct mohdata));
- if (!moh)
+ long flags;
+ if (!(moh = ast_calloc(1, sizeof(*moh))))
return NULL;
- memset(moh, 0, sizeof(struct mohdata));
if (pipe(moh->pipe)) {
ast_log(LOG_WARNING, "Failed to create pipe: %s\n", strerror(errno));
free(moh);
@@ -669,8 +666,7 @@ static void *moh_alloc(struct ast_channel *chan, void *params)
struct mohdata *res;
struct mohclass *class = params;
- res = mohalloc(class);
- if (res) {
+ if ((res = mohalloc(class))) {
res->origwfmt = chan->writeformat;
if (ast_set_write_format(chan, class->format)) {
ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", chan->name, ast_codec2str(class->format));
@@ -907,14 +903,8 @@ static struct mohclass *moh_class_malloc(void)
{
struct mohclass *class;
- class = malloc(sizeof(struct mohclass));
-
- if (!class)
- return NULL;
-
- memset(class, 0, sizeof(struct mohclass));
-
- class->format = AST_FORMAT_SLINEAR;
+ if ((class = ast_calloc(1, sizeof(*class))))
+ class->format = AST_FORMAT_SLINEAR;
return class;
}
@@ -937,10 +927,8 @@ static int load_moh_classes(int reload)
cat = ast_category_browse(cfg, NULL);
for (; cat; cat = ast_category_browse(cfg, cat)) {
- if (strcasecmp(cat, "classes") && strcasecmp(cat, "moh_files")) {
- class = moh_class_malloc();
- if (!class) {
- ast_log(LOG_WARNING, "Out of memory!\n");
+ if (strcasecmp(cat, "classes") && strcasecmp(cat, "moh_files")) {
+ if (!(class = moh_class_malloc())) {
break;
}
ast_copy_string(class->name, cat, sizeof(class->name));
@@ -1005,10 +993,8 @@ static int load_moh_classes(int reload)
args = strchr(data, ',');
if (args)
*args++ = '\0';
- if (!(get_mohbyname(var->name))) {
- class = moh_class_malloc();
- if (!class) {
- ast_log(LOG_WARNING, "Out of memory!\n");
+ if (!(get_mohbyname(var->name))) {
+ if (!(class = moh_class_malloc())) {
return numclasses;
}
@@ -1033,10 +1019,8 @@ static int load_moh_classes(int reload)
if (!(get_mohbyname(var->name))) {
args = strchr(var->value, ',');
if (args)
- *args++ = '\0';
- class = moh_class_malloc();
- if (!class) {
- ast_log(LOG_WARNING, "Out of memory!\n");
+ *args++ = '\0';
+ if (!(class = moh_class_malloc())) {
return numclasses;
}