diff options
-rw-r--r-- | apps/app_queue.c | 32 | ||||
-rw-r--r-- | apps/app_rpt.c | 56 | ||||
-rw-r--r-- | apps/app_voicemail.c | 58 |
3 files changed, 54 insertions, 92 deletions
diff --git a/apps/app_queue.c b/apps/app_queue.c index 7afb2a83d..ab4b2af97 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -514,9 +514,8 @@ static int statechange_queue(const char *dev, int state, void *ign) struct statechange *sc; pthread_t t; pthread_attr_t attr; - - sc = ast_calloc(1, sizeof(*sc) + strlen(dev) + 1); - if (sc) { + + if ((sc = ast_calloc(1, sizeof(*sc) + strlen(dev) + 1))) { sc->state = state; strcpy(sc->dev, dev); pthread_attr_init(&attr); @@ -535,9 +534,7 @@ static struct member *create_queue_member(char *interface, int penalty, int paus /* Add a new member */ - cur = ast_calloc(1, sizeof(*cur)); - - if (cur) { + if ((cur = ast_calloc(1, sizeof(*cur)))) { cur->penalty = penalty; cur->paused = paused; ast_copy_string(cur->interface, interface, sizeof(cur->interface)); @@ -553,8 +550,7 @@ static struct ast_call_queue *alloc_queue(const char *queuename) { struct ast_call_queue *q; - q = ast_calloc(1, sizeof(*q)); - if (q) { + if ((q = ast_calloc(1, sizeof(*q)))) { ast_mutex_init(&q->lock); ast_copy_string(q->name, queuename, sizeof(q->name)); } @@ -827,8 +823,7 @@ static struct ast_call_queue *find_queue_by_name_rt(const char *queuename, struc /* Create a new queue if an in-core entry does not exist yet. */ if (!q) { - q = alloc_queue(queuename); - if (!q) + if (!(q = alloc_queue(queuename))) return NULL; ast_mutex_lock(&q->lock); clear_queue(q); @@ -1704,11 +1699,8 @@ static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser if (in->cid.cid_ani) { if (o->chan->cid.cid_ani) free(o->chan->cid.cid_ani); - o->chan->cid.cid_ani = ast_calloc(1, strlen(in->cid.cid_ani) + 1); - if (o->chan->cid.cid_ani) + if ((o->chan->cid.cid_ani = ast_calloc(1, strlen(in->cid.cid_ani) + 1))) strncpy(o->chan->cid.cid_ani, in->cid.cid_ani, strlen(in->cid.cid_ani) + 1); - else - ast_log(LOG_WARNING, "Out of memory\n"); } if (o->chan->cid.cid_rdnis) free(o->chan->cid.cid_rdnis); @@ -2060,12 +2052,10 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce announce = announceoverride; while(cur) { - tmp = ast_calloc(1, sizeof(*tmp)); - if (!tmp) { + if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { ast_mutex_unlock(&qe->parent->lock); if (use_weight) ast_mutex_unlock(&qlock); - ast_log(LOG_WARNING, "Out of memory\n"); goto out; } tmp->stillgoing = -1; @@ -3204,7 +3194,9 @@ static void reload_queues(void) } if (!q) { /* Make one then */ - q = alloc_queue(cat); + if (!(q = alloc_queue(cat))) { + /* TODO: Handle memory allocation failure */ + } new = 1; } else new = 0; @@ -3681,8 +3673,8 @@ static char *complete_add_queue_member(char *line, char *word, int pos, int stat } case 7: if (state < 100) { /* 0-99 */ - char *num = ast_malloc(3); - if (num) { + char *num; + if ((num = ast_malloc(3))) { sprintf(num, "%d", state); } return num; diff --git a/apps/app_rpt.c b/apps/app_rpt.c index cc1f1038b..9deba11c1 100644 --- a/apps/app_rpt.c +++ b/apps/app_rpt.c @@ -1041,8 +1041,7 @@ struct tm localtm; /* allocate a pseudo-channel thru asterisk */ - mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!mychannel) + if (!(mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); ast_mutex_lock(&myrpt->lock); @@ -1312,11 +1311,9 @@ struct tm localtm; { l = l->next; continue; - } - m = ast_malloc(sizeof(*m)); - if (!m) + } + if (!(m = ast_malloc(sizeof(*m)))) { - ast_log(LOG_WARNING, "Cannot alloc memory on %s\n", mychannel->name); ast_mutex_lock(&myrpt->lock); remque((struct qelem *)mytele); ast_mutex_unlock(&myrpt->lock); @@ -1563,16 +1560,12 @@ static void rpt_telemetry(struct rpt *myrpt,int mode, void *data) struct rpt_tele *tele; struct rpt_link *mylink = (struct rpt_link *) data; pthread_attr_t attr; - - tele = ast_malloc(sizeof(*tele)); - if (!tele) + + if (!(tele = ast_calloc(1, sizeof(*tele)))) { - ast_log(LOG_WARNING, "Unable to allocate memory\n"); pthread_exit(NULL); return; } - /* zero it out */ - memset((char *)tele,0,sizeof(struct rpt_tele)); tele->rpt = myrpt; tele->mode = mode; ast_mutex_lock(&myrpt->lock); @@ -1605,8 +1598,7 @@ struct ast_channel *mychannel,*genchannel; myrpt->mydtmf = 0; /* allocate a pseudo-channel thru asterisk */ - mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!mychannel) + if (!(mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); pthread_exit(NULL); @@ -1624,8 +1616,7 @@ struct ast_channel *mychannel,*genchannel; pthread_exit(NULL); } /* allocate a pseudo-channel thru asterisk */ - genchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!genchannel) + if (!(genchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); ast_hangup(mychannel); @@ -1951,10 +1942,8 @@ static int function_ilink(struct rpt *myrpt, char *param, char *digits, int comm } else ast_mutex_unlock(&myrpt->lock); strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1); - /* establish call in monitor mode */ - l = ast_calloc(1, sizeof(*l)); - if (!l){ - ast_log(LOG_WARNING, "Unable to malloc\n"); + /* establish call in monitor mode */ + if (!(l = ast_calloc(1, sizeof(*l)))) { return DC_ERROR; } /* zero the silly thing */ @@ -1993,8 +1982,7 @@ static int function_ilink(struct rpt *myrpt, char *param, char *digits, int comm return DC_ERROR; } /* allocate a pseudo-channel thru asterisk */ - l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!l->pchan){ + if (!(l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); ast_hangup(l->chan); free(l); @@ -2065,9 +2053,7 @@ static int function_ilink(struct rpt *myrpt, char *param, char *digits, int comm ast_mutex_unlock(&myrpt->lock); strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1); /* establish call in tranceive mode */ - l = ast_calloc(1, sizeof(*l)); - if (!l){ - ast_log(LOG_WARNING, "Unable to malloc\n"); + if (!(l = ast_calloc(1, sizeof(*l)))) { return(DC_ERROR); } l->mode = 1; @@ -2107,8 +2093,7 @@ static int function_ilink(struct rpt *myrpt, char *param, char *digits, int comm return DC_ERROR; } /* allocate a pseudo-channel thru asterisk */ - l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!l->pchan){ + if (!(l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); ast_hangup(l->chan); free(l); @@ -4711,8 +4696,7 @@ char cmd[MAXDTMF+1] = ""; ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY); ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY); /* allocate a pseudo-channel thru asterisk */ - myrpt->pchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!myrpt->pchannel) + if (!(myrpt->pchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); ast_mutex_unlock(&myrpt->lock); @@ -4760,8 +4744,7 @@ char cmd[MAXDTMF+1] = ""; /* save pseudo channel conference number */ myrpt->conf = ci.confno; /* allocate a pseudo-channel thru asterisk */ - myrpt->txpchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!myrpt->txpchannel) + if (!(myrpt->txpchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); ast_mutex_unlock(&myrpt->lock); @@ -6014,9 +5997,7 @@ static int rpt_exec(struct ast_channel *chan, void *data) } l=strlen(options)+2; - orig_s=ast_malloc(l); - if(!orig_s) { - ast_log(LOG_WARNING, "Out of memory\n"); + if (!(orig_s = ast_malloc(l))) { return -1; } s=orig_s; @@ -6226,10 +6207,8 @@ static int rpt_exec(struct ast_channel *chan, void *data) } else ast_mutex_unlock(&myrpt->lock); /* establish call in tranceive mode */ - l = ast_calloc(1, sizeof(*l)); - if (!l) + if (!(l = ast_calloc(1, sizeof(*l)))) { - ast_log(LOG_WARNING, "Unable to malloc\n"); pthread_exit(NULL); } l->mode = 1; @@ -6242,8 +6221,7 @@ static int rpt_exec(struct ast_channel *chan, void *data) ast_set_read_format(l->chan,AST_FORMAT_SLINEAR); ast_set_write_format(l->chan,AST_FORMAT_SLINEAR); /* allocate a pseudo-channel thru asterisk */ - l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL); - if (!l->pchan) + if (!(l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL))) { fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n"); pthread_exit(NULL); diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index f3d6c1df7..3c958d994 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -532,12 +532,7 @@ static struct ast_vm_user *find_user_realtime(struct ast_vm_user *ivm, const cha struct ast_variable *var, *tmp; struct ast_vm_user *retval; - if (ivm) - retval=ivm; - else - retval=ast_calloc(1, sizeof(*retval)); - - if (retval) { + if ((retval = (ivm ? ivm : ast_calloc(1, sizeof(*retval))))) { if (!ivm) ast_set_flag(retval, VM_ALLOCED); else @@ -596,12 +591,8 @@ static struct ast_vm_user *find_user(struct ast_vm_user *ivm, const char *contex cur=cur->next; } if (cur) { - if (ivm) - vmu = ivm; - else - /* Make a copy, so that on a reload, we have no race */ - vmu = ast_malloc(sizeof(*vmu)); - if (vmu) { + /* Make a copy, so that on a reload, we have no race */ + if ((vmu = (ivm ? ivm : ast_malloc(sizeof(*vmu))))) { memcpy(vmu, cur, sizeof(*vmu)); ast_set2_flag(vmu, !ivm, VM_ALLOCED); vmu->next = NULL; @@ -1462,7 +1453,7 @@ static int vm_delete(char *file) int txtsize = 0; txtsize = (strlen(file) + 5)*sizeof(char); - txt = (char *)alloca(txtsize); + txt = alloca(txtsize); /* Sprintf here would safe because we alloca'd exactly the right length, * but trying to eliminate all sprintf's anyhow */ @@ -1689,8 +1680,8 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *c strftime(date, sizeof(date), emaildateformat, &tm); if (*fromstring) { - struct ast_channel *ast = ast_channel_alloc(0); - if (ast) { + struct ast_channel *ast; + if ((ast = ast_channel_alloc(0))) { char *passdata; int vmlen = strlen(fromstring)*3 + 200; if ((passdata = alloca(vmlen))) { @@ -1706,8 +1697,8 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *c fprintf(p, "To: %s <%s>\n", vmu->fullname, vmu->email); if (emailsubject) { - struct ast_channel *ast = ast_channel_alloc(0); - if (ast) { + struct ast_channel *ast; + if ((ast = ast_channel_alloc(0))) { char *passdata; int vmlen = strlen(emailsubject)*3 + 200; if ((passdata = alloca(vmlen))) { @@ -1738,8 +1729,8 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *c } fprintf(p, "Content-Type: text/plain; charset=%s\nContent-Transfer-Encoding: 8bit\n\n", charset); if (emailbody) { - struct ast_channel *ast = ast_channel_alloc(0); - if (ast) { + struct ast_channel *ast; + if ((ast = ast_channel_alloc(0))) { char *passdata; int vmlen = strlen(emailbody)*3 + 200; if ((passdata = alloca(vmlen))) { @@ -1807,8 +1798,8 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char fprintf(p, "Date: %s\n", date); if (*pagerfromstring) { - struct ast_channel *ast = ast_channel_alloc(0); - if (ast) { + struct ast_channel *ast; + if ((ast = ast_channel_alloc(0))) { char *passdata; int vmlen = strlen(fromstring)*3 + 200; if ((passdata = alloca(vmlen))) { @@ -1824,8 +1815,8 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char fprintf(p, "From: Asterisk PBX <%s>\n", who); fprintf(p, "To: %s\n", pager); if (pagersubject) { - struct ast_channel *ast = ast_channel_alloc(0); - if (ast) { + struct ast_channel *ast; + if ((ast = ast_channel_alloc(0))) { char *passdata; int vmlen = strlen(pagersubject)*3 + 200; if ((passdata = alloca(vmlen))) { @@ -1840,8 +1831,8 @@ static int sendpage(char *srcemail, char *pager, int msgnum, char *context, char fprintf(p, "Subject: New VM\n\n"); strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm); if (pagerbody) { - struct ast_channel *ast = ast_channel_alloc(0); - if (ast) { + struct ast_channel *ast; + if ((ast = ast_channel_alloc(0))) { char *passdata; int vmlen = strlen(pagerbody)*3 + 200; if ((passdata = alloca(vmlen))) { @@ -5138,8 +5129,12 @@ static int vm_execmain(struct ast_channel *chan, void *data) if (!valid) goto out; - vms.deleted = calloc(vmu->maxmsg, sizeof(int)); - vms.heard = calloc(vmu->maxmsg, sizeof(int)); + if (!(vms.deleted = ast_calloc(vmu->maxmsg, sizeof(int)))) { + /* TODO: Handle memory allocation failure */ + } + if (!(vms.heard = ast_calloc(vmu->maxmsg, sizeof(int)))) { + /* TODO: Handle memory allocation failure */ + } /* Set language from config to override channel language */ if (!ast_strlen_zero(vmu->language)) @@ -5592,8 +5587,7 @@ static int append_mailbox(char *context, char *mbox, char *data) struct ast_vm_user *vmu; ast_copy_string(tmp, data, sizeof(tmp)); - vmu = ast_calloc(1, sizeof(*vmu)); - if (vmu) { + if ((vmu = ast_calloc(1, sizeof(*vmu)))) { ast_copy_string(vmu->context, context, sizeof(vmu->context)); ast_copy_string(vmu->mailbox, mbox, sizeof(vmu->mailbox)); @@ -6129,8 +6123,7 @@ static int load_config(void) /* Timezones in this context */ while (var) { struct vm_zone *z; - z = ast_malloc(sizeof(*z)); - if (z != NULL) { + if ((z = ast_malloc(sizeof(*z)))) { char *msg_format, *timezone; msg_format = ast_strdupa(var->value); if (msg_format != NULL) { @@ -6156,8 +6149,7 @@ static int load_config(void) free(z); return -1; } - } else { - ast_log(LOG_WARNING, "Out of memory while reading voicemail config\n"); + } else { return -1; } var = var->next; |