Index: channels/misdn_config.c =================================================================== --- channels/misdn_config.c (revision 67164) +++ channels/misdn_config.c (working copy) @@ -445,8 +445,8 @@ if (iter->next) _free_msn_list(iter->next); if (iter->msn) - free(iter->msn); - free(iter); + ast_free(iter->msn); + ast_free(iter); } static void _free_port_cfg (void) @@ -476,7 +476,7 @@ if (port_spec[i].type == MISDN_CTYPE_MSNLIST) _free_msn_list(free_list[j][i].ml); else - free(free_list[j][i].any); + ast_free(free_list[j][i].any); } } } @@ -488,7 +488,7 @@ for (i = 0; i < NUM_GEN_ELEMENTS; i++) if (general_cfg[i].any) - free(general_cfg[i].any); + ast_free(general_cfg[i].any); } void misdn_cfg_get (int port, enum misdn_cfg_elements elem, void *buf, int bufsize) @@ -850,11 +850,11 @@ switch (type) { case MISDN_CTYPE_STR: if ((len = strlen(value))) { - dest->str = (char *)malloc((len + 1) * sizeof(char)); + dest->str = ast_malloc((len + 1) * sizeof(char)); strncpy(dest->str, value, len); dest->str[len] = 0; } else { - dest->str = (char *)malloc( sizeof(char)); + dest->str = ast_malloc(sizeof(char)); dest->str[0] = 0; } break; @@ -866,18 +866,18 @@ else pat="%d"; if (sscanf(value, pat, &tmp)) { - dest->num = (int *)malloc(sizeof(int)); + dest->num = ast_malloc(sizeof(int)); memcpy(dest->num, &tmp, sizeof(int)); } else re = -1; } break; case MISDN_CTYPE_BOOL: - dest->num = (int *)malloc(sizeof(int)); + dest->num = ast_malloc(sizeof(int)); *(dest->num) = (ast_true(value) ? 1 : 0); break; case MISDN_CTYPE_BOOLINT: - dest->num = (int *)malloc(sizeof(int)); + dest->num = ast_malloc(sizeof(int)); if (sscanf(value, "%d", &tmp)) { memcpy(dest->num, &tmp, sizeof(int)); } else { @@ -887,8 +887,8 @@ case MISDN_CTYPE_MSNLIST: for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) { if ((len = strlen(valtmp))) { - struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list)); - ml->msn = (char *)calloc(len+1, sizeof(char)); + struct msn_list *ml = ast_malloc(sizeof(*ml)); + ml->msn = ast_calloc(len+1, sizeof(char)); strncpy(ml->msn, valtmp, len); ml->next = dest->ml; dest->ml = ml; @@ -896,7 +896,7 @@ } break; case MISDN_CTYPE_ASTGROUP: - dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t)); + dest->grp = ast_malloc(sizeof(ast_group_t)); *(dest->grp) = ast_get_group(value); break; } @@ -1059,10 +1059,10 @@ _free_port_cfg(); _free_general_cfg(); - free(port_cfg); - free(general_cfg); - free(ptp); - free(map); + ast_free(port_cfg); + ast_free(general_cfg); + ast_free(ptp); + ast_free(map); misdn_cfg_unlock(); ast_mutex_destroy(&config_mutex); @@ -1088,10 +1088,10 @@ if (this_max_ports) { /* this is the first run */ max_ports = this_max_ports; - map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int)); + map = ast_calloc(MISDN_GEN_LAST + 1, sizeof(int)); if (_enum_array_map()) return -1; - p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *) + p = ast_calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *) + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt)); port_cfg = (union misdn_cfg_pt **)p; p += (max_ports + 1) * sizeof(union misdn_cfg_pt *); @@ -1099,8 +1099,8 @@ port_cfg[i] = (union misdn_cfg_pt *)p; p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt); } - general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); - ptp = (int *)calloc(max_ports + 1, sizeof(int)); + general_cfg = ast_calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); + ptp = ast_calloc(max_ports + 1, sizeof(int)); } else { /* misdn reload */ Index: channels/chan_zap.c =================================================================== --- channels/chan_zap.c (revision 67164) +++ channels/chan_zap.c (working copy) @@ -1882,7 +1882,7 @@ return 0; p->cidpos += res; } - free(p->cidspill); + ast_free(p->cidspill); p->cidspill = NULL; if (p->callwaitcas) { /* Wait for CID/CW to expire */ @@ -1898,7 +1898,7 @@ p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES; if (p->cidspill) { ast_log(LOG_WARNING, "Spill already exists?!?\n"); - free(p->cidspill); + ast_free(p->cidspill); } if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4))) return -1; @@ -1975,7 +1975,7 @@ /* Generate the Caller-ID spill if desired */ if (p->cidspill) { ast_log(LOG_WARNING, "cidspill already exists??\n"); - free(p->cidspill); + ast_free(p->cidspill); } p->callwaitcas = 0; if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) { @@ -2417,7 +2417,7 @@ if (p->mwi_event_sub) ast_event_unsubscribe(p->mwi_event_sub); ast_mutex_destroy(&p->lock); - free(p); + ast_free(p); *pvt = NULL; } @@ -2640,12 +2640,12 @@ restore_gains(p); if (p->origcid_num) { ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num)); - free(p->origcid_num); + ast_free(p->origcid_num); p->origcid_num = NULL; } if (p->origcid_name) { ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name)); - free(p->origcid_name); + ast_free(p->origcid_name); p->origcid_name = NULL; } if (p->dsp) @@ -2908,7 +2908,7 @@ tone_zone_play_tone(p->subs[SUB_REAL].zfd, -1); } if (p->cidspill) - free(p->cidspill); + ast_free(p->cidspill); if (p->sig) zt_disable_ec(p); x = 0; @@ -3891,7 +3891,7 @@ if ((f->subclass == 'A') || (f->subclass == 'D')) { ast_log(LOG_DEBUG, "Got some DTMF, but it's for the CAS\n"); if (p->cidspill) - free(p->cidspill); + ast_free(p->cidspill); send_cwcidspill(p); } if ((f->subclass != 'm') && (f->subclass != 'u')) @@ -4289,7 +4289,7 @@ ast_log(LOG_DEBUG, "channel %d answered\n", p->channel); if (p->cidspill) { /* Cancel any running CallerID spill */ - free(p->cidspill); + ast_free(p->cidspill); p->cidspill = NULL; } p->dialing = 0; @@ -4419,7 +4419,7 @@ ast->rings++; if ((ast->rings > p->cidrings) && (p->cidspill)) { ast_log(LOG_WARNING, "Didn't finish Caller-ID spill. Cancelling.\n"); - free(p->cidspill); + ast_free(p->cidspill); p->cidspill = NULL; p->callwaitcas = 0; } @@ -5529,7 +5529,7 @@ y = 1; do { if (b2) - free(b2); + ast_free(b2); #ifdef HAVE_PRI if (i->bearer || (i->pri && (i->sig == SIG_FXSKS))) asprintf(&b2, "%d:%d-%d", i->pri->trunkgroup, i->channel, y); @@ -5547,7 +5547,7 @@ } while (x < 3); tmp = ast_channel_alloc(0, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "Zap/%s", b2); if (b2) /*!> b2 can be freed now, it's been copied into the channel structure */ - free(b2); + ast_free(b2); if (!tmp) return NULL; tmp->tech = &zap_tech; @@ -6245,10 +6245,10 @@ /* Disable Caller*ID if enabled */ p->hidecallerid = 1; if (chan->cid.cid_num) - free(chan->cid.cid_num); + ast_free(chan->cid.cid_num); chan->cid.cid_num = NULL; if (chan->cid.cid_name) - free(chan->cid.cid_name); + ast_free(chan->cid.cid_name); chan->cid.cid_name = NULL; res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL); if (res) { @@ -6327,10 +6327,10 @@ /* Enable Caller*ID if enabled */ p->hidecallerid = 0; if (chan->cid.cid_num) - free(chan->cid.cid_num); + ast_free(chan->cid.cid_num); chan->cid.cid_num = NULL; if (chan->cid.cid_name) - free(chan->cid.cid_name); + ast_free(chan->cid.cid_name); chan->cid.cid_name = NULL; ast_set_callerid(chan, p->cid_num, p->cid_name, NULL); res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL); @@ -6957,7 +6957,7 @@ break; if (i->cidspill) { /* Cancel VMWI spill */ - free(i->cidspill); + ast_free(i->cidspill); i->cidspill = NULL; } if (i->immediate) { @@ -7157,7 +7157,7 @@ ast_mutex_lock(&iflock); if (!pfds || (lastalloc != ifcount)) { if (pfds) - free(pfds); + ast_free(pfds); if (ifcount) { if (!(pfds = ast_calloc(1, ifcount * sizeof(*pfds)))) { ast_mutex_unlock(&iflock); @@ -7278,7 +7278,7 @@ if (res2 > 0) { i->cidpos += res2; if (i->cidpos >= i->cidlen) { - free(i->cidspill); + ast_free(i->cidspill); i->cidspill = 0; i->cidpos = 0; i->cidlen = 0; @@ -10623,7 +10623,7 @@ info_str = pri_dump_info_str(pris[span-1].pri); if (info_str) { ast_cli(fd, "%s", info_str); - free(info_str); + ast_free(info_str); } #else pri_dump_info(pris[span-1].pri); @@ -11419,7 +11419,7 @@ while (p) { /* Free any callerid */ if (p->cidspill) - free(p->cidspill); + ast_free(p->cidspill); /* Close the zapata thingy */ if (p->subs[SUB_REAL].zfd > -1) zt_close(p->subs[SUB_REAL].zfd); @@ -12877,7 +12877,7 @@ len = tdd_generate(p->tdd, buf, text); if (len < 1) { ast_log(LOG_ERROR, "TDD generate (len %d) failed!!\n", (int)strlen(text)); - free(mybuf); + ast_free(mybuf); return -1; } } @@ -12886,7 +12886,7 @@ fd = p->subs[index].zfd; while (len) { if (ast_check_hangup(c)) { - free(mybuf); + ast_free(mybuf); return -1; } size = len; @@ -12912,7 +12912,7 @@ res = write(fd, buf, size); if (res != size) { if (res == -1) { - free(mybuf); + ast_free(mybuf); return -1; } if (option_debug) @@ -12922,7 +12922,7 @@ len -= size; buf += size; } - free(mybuf); + ast_free(mybuf); return(0); } Index: channels/chan_vpb.cc =================================================================== --- channels/chan_vpb.cc (revision 67164) +++ channels/chan_vpb.cc (working copy) @@ -679,10 +679,10 @@ if ((rc=vpb_cid_decode2(cli_struct, buf, CID_MSECS*8)) == VPB_OK ) { /* if (owner->cid.cid_num) - free(owner->cid.cid_num); + ast_free(owner->cid.cid_num); owner->cid.cid_num=NULL; if (owner->cid.cid_name) - free(owner->cid.cid_name); + ast_free(owner->cid.cid_name); owner->cid.cid_name=NULL; */ @@ -791,11 +791,11 @@ ast_log(LOG_ERROR, "%s: Failed to create Caller ID struct\n", p->dev ); } if (owner->cid.cid_num) { - free(owner->cid.cid_num); + ast_free(owner->cid.cid_num); owner->cid.cid_num = NULL; } if (owner->cid.cid_name) { - free(owner->cid.cid_name); + ast_free(owner->cid.cid_name); owner->cid.cid_name = NULL; } if (number) @@ -1239,10 +1239,10 @@ if (owner){ /* if (owner->cid.cid_num) - free(owner->cid.cid_num); + ast_free(owner->cid.cid_num); owner->cid.cid_num=NULL; if (owner->cid.cid_name) - free(owner->cid.cid_name); + ast_free(owner->cid.cid_name); owner->cid.cid_name=NULL; owner->cid.cid_num = strdup(p->callerid); */ @@ -1499,11 +1499,10 @@ if(!bridges) { if(model==vpb_model_v4pci) max_bridges = MAX_BRIDGES_V4PCI; - bridges = (vpb_bridge_t *)malloc(max_bridges * sizeof(vpb_bridge_t) ); + bridges = ast_calloc(1, max_bridges * sizeof(vpb_bridge_t)); if(!bridges) ast_log(LOG_ERROR, "Failed to initialize bridges\n"); else { - memset(bridges,0,max_bridges * sizeof(vpb_bridge_t)); for(int i = 0; i < max_bridges; i++ ) { ast_mutex_init(&bridges[i].lock); ast_cond_init(&bridges[i].cond, NULL); @@ -1544,7 +1543,7 @@ struct vpb_pvt *tmp; char buf[64]; - tmp = (struct vpb_pvt *)calloc(1, sizeof *tmp); + tmp = ast_calloc(1, sizeof(*tmp)); if (!tmp) return NULL; @@ -1554,7 +1553,7 @@ if (tmp->handle < 0) { ast_log(LOG_WARNING, "Unable to create channel vpb/%d-%d: %s\n", board, channel, strerror(errno)); - free(tmp); + ast_free(tmp); return NULL; } @@ -2741,7 +2740,7 @@ ast_verbose(VERBOSE_PREFIX_2 " %s requested, got: [%s]\n", name, tmp ? tmp->name : "None"); - free(name); + ast_free(name); restart_monitor(); return tmp; @@ -2814,7 +2813,7 @@ iflist = iflist->next; - free(p); + ast_free(p); } iflist = NULL; } ast_mutex_unlock(&iflock); @@ -2827,7 +2826,7 @@ ast_mutex_destroy(&bridges[i].lock); ast_cond_destroy(&bridges[i].cond); } - free(bridges); + ast_free(bridges); return 0; } Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 67164) +++ channels/chan_sip.c (working copy) @@ -1791,7 +1791,7 @@ static struct sip_proxy *proxy_allocate(char *name, char *port, int force) { struct sip_proxy *proxy; - proxy = ast_calloc(1, sizeof(struct sip_proxy)); + proxy = ast_calloc(1, sizeof(*proxy)); if (!proxy) return NULL; proxy->force = force; @@ -2015,7 +2015,7 @@ if (!(hist = ast_calloc(1, sizeof(*hist) + l))) return; if (!p->history && !(p->history = ast_calloc(1, sizeof(*p->history)))) { - free(hist); + ast_free(hist); return; } memcpy(hist->event, buf, l); @@ -2141,7 +2141,7 @@ if (cur == pkt) { UNLINK(cur, pkt->owner->packets, prev); sip_pvt_unlock(pkt->owner); - free(pkt); + ast_free(pkt); return 0; } } @@ -2300,7 +2300,7 @@ cur->retransid = -1; } UNLINK(cur, p->packets, prev); - free(cur); + ast_free(cur); break; } } @@ -2708,7 +2708,7 @@ ast_log(LOG_DEBUG, "Destroying SIP peer %s\n", peer->name); if (peer->outboundproxy) - free(peer->outboundproxy); + ast_free(peer->outboundproxy); /* Delete it, it needs to disappear */ if (peer->call) @@ -2745,7 +2745,7 @@ peer->auth = NULL; if (peer->dnsmgr) ast_dnsmgr_release(peer->dnsmgr); - free(peer); + ast_free(peer); } /*! \brief Update peer data in database (if used) */ @@ -2903,7 +2903,7 @@ ruserobjs--; else suserobjs--; - free(user); + ast_free(user); } /*! \brief Load user from realtime storage @@ -3304,7 +3304,7 @@ ast_sched_del(sched, reg->timeout); ast_string_field_free_pools(reg); regobjs--; - free(reg); + ast_free(reg); } @@ -3331,7 +3331,7 @@ sip_dump_history(p); if (p->options) - free(p->options); + ast_free(p->options); if (p->stateid > -1) ast_extension_state_del(p->stateid, NULL); @@ -3349,7 +3349,7 @@ if (p->udptl) ast_udptl_destroy(p->udptl); if (p->refer) - free(p->refer); + ast_free(p->refer); if (p->route) { free_old_route(p->route); p->route = NULL; @@ -3374,8 +3374,8 @@ if (p->history) { struct sip_history *hist; while( (hist = AST_LIST_REMOVE_HEAD(p->history, list)) ) - free(hist); - free(p->history); + ast_free(hist); + ast_free(p->history); p->history = NULL; } @@ -3400,7 +3400,7 @@ p->packets = p->packets->next; if (cp->retransid > -1) ast_sched_del(sched, cp->retransid); - free(cp); + ast_free(cp); } if (p->chanvars) { ast_variables_destroy(p->chanvars); @@ -3410,7 +3410,7 @@ ast_string_field_free_pools(p); - free(p); + ast_free(p); } /*! \brief update_call_counter: Handle call_limit for SIP users @@ -4686,7 +4686,7 @@ return NULL; if (ast_string_field_init(p, 512)) { - free(p); + ast_free(p); return NULL; } @@ -4738,7 +4738,7 @@ ast_variables_destroy(p->chanvars); p->chanvars = NULL; } - free(p); + ast_free(p); return NULL; } ast_rtp_setqos(p->rtp, global_tos_audio, global_cos_audio); @@ -4997,7 +4997,7 @@ if (ast_string_field_init(reg, 256)) { ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry strings\n"); - free(reg); + ast_free(reg); return -1; } @@ -6334,7 +6334,7 @@ ast_string_field_free_pools(p); - free(data); + ast_free(data); } /*! \brief Transmit response, no retransmits, using a temporary pvt structure */ @@ -8601,7 +8601,7 @@ while (route) { next = route->next; - free(route); + ast_free(route); route = next; } } @@ -13572,7 +13572,7 @@ transferee = d->chan1; transferer = d->chan2; copy_request(&req, &d->req); - free(d); + ast_free(d); if (!transferee || !transferer) { ast_log(LOG_ERROR, "Missing channels for parking! Transferer %s Transferee %s\n", transferer ? "" : "", transferee ? "" : "" ); @@ -13704,7 +13704,7 @@ d->seqno = seqno; if (ast_pthread_create_detached_background(&th, NULL, sip_park_thread, d) < 0) { /* Could not start thread */ - free(d); /* We don't need it anymore. If thread is created, d will be free'd + ast_free(d); /* We don't need it anymore. If thread is created, d will be free'd by sip_park_thread() */ return 0; } @@ -16663,7 +16663,7 @@ AST_LIST_LOCK(&domain_list); while ((d = AST_LIST_REMOVE_HEAD(&domain_list, list))) - free(d); + ast_free(d); AST_LIST_UNLOCK(&domain_list); } @@ -16736,7 +16736,7 @@ while (a) { b = a; a = a->next; - free(b); + ast_free(b); } return 1; @@ -17224,7 +17224,7 @@ asprintf(®_string, "%s:%s@%s/%s", peer->username, peer->secret, peer->tohost, callback); if (reg_string) { sip_register(reg_string, 0); /* XXX TODO: count in registry_count */ - free(reg_string); + ast_free(reg_string); } } return peer; @@ -18645,7 +18645,7 @@ sched_context_destroy(sched); if (global_disclaimer) - free(global_disclaimer); + ast_free(global_disclaimer); return 0; } Index: channels/chan_agent.c =================================================================== --- channels/chan_agent.c (revision 67164) +++ channels/chan_agent.c (working copy) @@ -378,7 +378,7 @@ if (p->dead) { ast_mutex_destroy(&p->lock); ast_mutex_destroy(&p->app_lock); - free(p); + ast_free(p); } return 0; } @@ -810,7 +810,7 @@ } else if (p->dead) { ast_mutex_destroy(&p->lock); ast_mutex_destroy(&p->app_lock); - free(p); + ast_free(p); } else { if (p->chan) { /* Not dead -- check availability now */ @@ -1136,7 +1136,7 @@ if (!p->chan) { ast_mutex_destroy(&p->lock); ast_mutex_destroy(&p->app_lock); - free(p); + ast_free(p); } else { /* Cause them to hang up */ ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT); @@ -2118,7 +2118,7 @@ if (p->dead && !p->owner) { ast_mutex_destroy(&p->lock); ast_mutex_destroy(&p->app_lock); - free(p); + ast_free(p); } } else { @@ -2531,7 +2531,7 @@ while ((p = AST_LIST_REMOVE_HEAD(&agents, list))) { if (p->owner) ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); - free(p); + ast_free(p); } AST_LIST_UNLOCK(&agents); AST_LIST_HEAD_DESTROY(&agents); Index: channels/iax2-provision.c =================================================================== --- channels/iax2-provision.c (revision 67164) +++ channels/iax2-provision.c (working copy) @@ -376,13 +376,12 @@ } if (!cur) { mallocd = 1; - cur = malloc(sizeof(struct iax_template)); + cur = ast_calloc(1, sizeof(*cur)); if (!cur) { ast_log(LOG_WARNING, "Out of memory!\n"); return -1; } /* Initialize entry */ - memset(cur, 0, sizeof(*cur)); strncpy(cur->name, s, sizeof(cur->name) - 1); cur->dead = 1; } @@ -527,7 +526,7 @@ prev->next = next; else templates = next; - free(cur); + ast_free(cur); } else prev = cur; cur = next; Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 67164) +++ channels/chan_iax2.c (working copy) @@ -962,7 +962,7 @@ if (ast_pthread_create_detached_background(&thread->threadid, NULL, iax2_process_thread, thread)) { ast_cond_destroy(&thread->cond); ast_mutex_destroy(&thread->lock); - free(thread); + ast_free(thread); thread = NULL; } @@ -1147,7 +1147,7 @@ return NULL; if (ast_string_field_init(tmp, 32)) { - free(tmp); + ast_free(tmp); tmp = NULL; return NULL; } @@ -1431,7 +1431,7 @@ munmap(cur->fwh, ntohl(cur->fwh->datalen) + sizeof(*(cur->fwh))); } close(cur->fd); - free(cur); + ast_free(cur); } static int try_firmware(char *s) @@ -1897,7 +1897,7 @@ jb_destroy(pvt->jb); /* gotta free up the stringfields */ ast_string_field_free_pools(pvt); - free(pvt); + ast_free(pvt); } } if (owner) { @@ -3174,7 +3174,7 @@ res = send_command_locked(PTR_TO_CALLNO(c->tech_pvt), AST_FRAME_CONTROL, AST_CONTROL_OPTION, 0, (unsigned char *) h, datalen + sizeof(*h), -1); - free(h); + ast_free(h); return res; } } @@ -5626,7 +5626,7 @@ return -1; if (ast_dnsmgr_lookup(hostname, ®->addr.sin_addr, ®->dnsmgr) < 0) { - free(reg); + ast_free(reg); return -1; } @@ -6235,10 +6235,10 @@ because by the time they could get tpeerlock, we've already grabbed it */ if (option_debug) ast_log(LOG_DEBUG, "Dropping unused iax2 trunk peer '%s:%d'\n", ast_inet_ntoa(drop->addr.sin_addr), ntohs(drop->addr.sin_port)); - free(drop->trunkdata); + ast_free(drop->trunkdata); ast_mutex_unlock(&drop->lock); ast_mutex_destroy(&drop->lock); - free(drop); + ast_free(drop); } @@ -6294,8 +6294,8 @@ struct dpreq_data *dpr = data; dp_lookup(dpr->callno, dpr->context, dpr->callednum, dpr->callerid, 0); if (dpr->callerid) - free(dpr->callerid); - free(dpr); + ast_free(dpr->callerid); + ast_free(dpr); return NULL; } @@ -6332,7 +6332,7 @@ d = stuff; chan1 = d->chan1; chan2 = d->chan2; - free(d); + ast_free(d); f = ast_read(chan1); if (f) ast_frfree(f); @@ -6387,7 +6387,7 @@ if (!ast_pthread_create_detached_background(&th, NULL, iax_park_thread, d)) { return 0; } - free(d); + ast_free(d); } return -1; } @@ -7256,7 +7256,7 @@ char tmp[256]; for (var = ies.vars; var; var = var->next) { if (prev) - free(prev); + ast_free(prev); prev = var; snprintf(tmp, sizeof(tmp), "__~IAX2~%s", var->name); pbx_builtin_setvar_helper(c, tmp, var->value); @@ -7973,7 +7973,7 @@ struct iax2_thread *thread = data; ast_mutex_destroy(&thread->lock); ast_cond_destroy(&thread->cond); - free(thread); + ast_free(thread); ast_atomic_dec_and_test(&iaxactivethreadcount); } @@ -8316,7 +8316,7 @@ while(con) { conl = con; con = con->next; - free(conl); + ast_free(conl); } } @@ -8496,10 +8496,11 @@ static int start_network_thread(void) { + struct iax2_thread *thread; int threadcount = 0; int x; for (x = 0; x < iaxthreadcount; x++) { - struct iax2_thread *thread = ast_calloc(1, sizeof(struct iax2_thread)); + thread = ast_calloc(1, sizeof(*thread)); if (thread) { thread->type = IAX_THREAD_TYPE_POOL; thread->threadnum = ++threadcount; @@ -8507,7 +8508,7 @@ ast_cond_init(&thread->cond, NULL); if (ast_pthread_create_detached(&thread->threadid, NULL, iax2_process_thread, thread)) { ast_log(LOG_WARNING, "Failed to create new thread!\n"); - free(thread); + ast_free(thread); thread = NULL; } AST_LIST_LOCK(&idle_list); @@ -8683,7 +8684,7 @@ peer->pokeexpire = -1; peer->sockfd = defaultsockfd; if (ast_string_field_init(peer, 32)) { - free(peer); + ast_free(peer); peer = NULL; } } @@ -8769,7 +8770,7 @@ ast_clear_flag(peer, IAX_DYNAMIC); if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr)) { ast_string_field_free_pools(peer); - free(peer); + ast_free(peer); return NULL; } if (!peer->addr.sin_port) @@ -8780,7 +8781,7 @@ } else if (!strcasecmp(v->name, "defaultip")) { if (ast_get_ip(&peer->defaddr, v->value)) { ast_string_field_free_pools(peer); - free(peer); + ast_free(peer); return NULL; } } else if (!strcasecmp(v->name, "sourceaddress")) { @@ -8934,7 +8935,7 @@ } else { AST_LIST_UNLOCK(&users); /* This is going to memset'd to 0 in the next block */ - user = ast_calloc(sizeof(*user),1); + user = ast_calloc(1, sizeof(*user)); } if (user) { @@ -8942,7 +8943,7 @@ ast_string_field_free_pools(user); memset(user, 0, sizeof(struct iax2_user)); if (ast_string_field_init(user, 32)) { - free(user); + ast_free(user); user = NULL; } user->maxauthreq = maxauthreq; @@ -9135,7 +9136,7 @@ } if (reg->dnsmgr) ast_dnsmgr_release(reg->dnsmgr); - free(reg); + ast_free(reg); } AST_LIST_UNLOCK(®istrations); @@ -9154,7 +9155,7 @@ user->vars = NULL; } ast_string_field_free_pools(user); - free(user); + ast_free(user); } static void prune_users(void) @@ -9198,7 +9199,7 @@ ast_string_field_free_pools(peer); - free(peer); + ast_free(peer); } static void prune_peers(void){ @@ -9751,7 +9752,7 @@ if ((dp->flags & CACHE_FLAG_PENDING) || dp->callno) ast_log(LOG_WARNING, "DP still has peer field or pending or callno (flags = %d, peer = blah, callno = %d)\n", dp->flags, dp->callno); else - free(dp); + ast_free(dp); continue; } if (!strcmp(dp->peercontext, data) && !strcmp(dp->exten, exten)) Index: channels/chan_oss.c =================================================================== --- channels/chan_oss.c (revision 67164) +++ channels/chan_oss.c (working copy) @@ -1306,7 +1306,7 @@ } else ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc); if (s) - free(s); + ast_free(s); return CLI_SUCCESS; } @@ -1362,7 +1362,7 @@ ast_cli(fd, "Failed to transfer :(\n"); } if (tmp) - free(tmp); + ast_free(tmp); return RESULT_SUCCESS; } @@ -1470,7 +1470,7 @@ } } if (o->mixer_cmd) - free(o->mixer_cmd); + ast_free(o->mixer_cmd); o->mixer_cmd = ast_strdup(s); ast_log(LOG_WARNING, "setting mixer %s\n", s); } @@ -1543,7 +1543,7 @@ asprintf(&cmd, "mixer %s", o->mixer_cmd); ast_log(LOG_WARNING, "running [%s]\n", cmd); system(cmd); - free(cmd); + ast_free(cmd); } if (o == &oss_default) /* we are done with the default */ return NULL; @@ -1574,7 +1574,7 @@ error: if (o != &oss_default) - free(o); + ast_free(o); return NULL; } Index: channels/chan_misdn.c =================================================================== --- channels/chan_misdn.c (revision 67164) +++ channels/chan_misdn.c (working copy) @@ -246,8 +246,8 @@ { if (r) { if (r->next) free_robin_list_r(r->next); - if (r->group) free(r->group); - free(r); + if (r->group) ast_free(r->group); + ast_free(r); } } @@ -259,12 +259,13 @@ static struct robin_list* get_robin_position (char *group) { + struct robin_list *new; struct robin_list *iter = robin; for (; iter; iter = iter->next) { if (!strcasecmp(iter->group, group)) return iter; } - struct robin_list *new = (struct robin_list *)calloc(1, sizeof(struct robin_list)); + new = ast_calloc(1, sizeof(*new)); new->group = strndup(group, strlen(group)); new->channel = 1; if (robin) { @@ -1914,7 +1915,7 @@ if ( !ast_strlen_zero(bc->rad) ) { if (ast->cid.cid_rdnis) - free(ast->cid.cid_rdnis); + ast_free(ast->cid.cid_rdnis); ast->cid.cid_rdnis = strdup(bc->rad); } @@ -2407,7 +2408,7 @@ cl_dequeue_chan(&cl_te, p); close(p->pipe[0]); close(p->pipe[1]); - free(p); + ast_free(p); if (bc) misdn_lib_release(bc); @@ -2965,15 +2966,15 @@ static struct chan_list *init_chan_list(int orig) { - struct chan_list *cl=malloc(sizeof(struct chan_list)); + struct chan_list *cl; + + cl = ast_calloc(1, sizeof(*cl)); if (!cl) { chan_misdn_log(-1, 0, "misdn_request: malloc failed!"); return NULL; } - memset(cl,0,sizeof(struct chan_list)); - cl->originator=orig; cl->need_queue_hangup=1; cl->need_hangup=1; @@ -3533,7 +3534,7 @@ ch->state=MISDN_CLEANING; cl_dequeue_chan(&cl_te, ch); - free(ch); + ast_free(ch); } else { /* chan is already cleaned, so exiting */ } @@ -4057,7 +4058,10 @@ struct ast_channel *chan; int exceed; - if (!ch) { chan_misdn_log(-1, bc->port, "cb_events: malloc for chan_list failed!\n"); return 0;} + if (!ch) { + chan_misdn_log(-1, bc->port, "cb_events: malloc for chan_list failed!\n"); + return 0; + } ch->bc = bc; ch->l3id=bc->l3_id; @@ -4824,10 +4828,10 @@ misdn_lib_destroy(); if (misdn_debug) - free(misdn_debug); + ast_free(misdn_debug); if (misdn_debug_only) - free(misdn_debug_only); - free(misdn_ports); + ast_free(misdn_debug_only); + ast_free(misdn_ports); return 0; } @@ -4851,15 +4855,23 @@ } g_config_initialized=1; - misdn_debug = (int *)malloc(sizeof(int) * (max_ports+1)); - misdn_ports = (int *)malloc(sizeof(int) * (max_ports+1)); + misdn_debug = ast_malloc(sizeof(int) * (max_ports+1)); + if (misdn_debug) { + ast_log(LOG_ERROR, "Out of memory for misdn_debug\n"); + return AST_MODULE_LOAD_DECLINE; + } + misdn_ports = ast_malloc(sizeof(int) * (max_ports+1)); + if (misdn_ports) { + ast_log(LOG_ERROR, "Out of memory for misdn_ports\n"); + return AST_MODULE_LOAD_DECLINE; + } misdn_cfg_get( 0, MISDN_GEN_DEBUG, &misdn_debug[0], sizeof(int)); for (i = 1; i <= max_ports; i++) { misdn_debug[i] = misdn_debug[0]; misdn_ports[i] = i; } *misdn_ports = 0; - misdn_debug_only = (int *)calloc(max_ports + 1, sizeof(int)); + misdn_debug_only = ast_calloc(max_ports + 1, sizeof(int)); { char tempbuf[BUFFERSIZE+1]; @@ -4868,8 +4880,8 @@ tracing = 1; } - misdn_in_calls = (int *)malloc(sizeof(int) * (max_ports+1)); - misdn_out_calls = (int *)malloc(sizeof(int) * (max_ports+1)); + misdn_in_calls = ast_malloc(sizeof(int) * (max_ports+1)); + misdn_out_calls = ast_malloc(sizeof(int) * (max_ports+1)); for (i=1; i <= max_ports; i++) { misdn_in_calls[i]=0; @@ -5341,7 +5353,13 @@ struct misdn_jb *misdn_jb_init(int size, int upper_threshold) { int i; - struct misdn_jb *jb = (struct misdn_jb*) malloc(sizeof(struct misdn_jb)); + struct misdn_jb *jb; + + jb = ast_malloc(sizeof(*jb)); + if (!jb) { + chan_misdn_log(-1,0,"No free Mem for jb\n"); + return NULL; + } jb->size = size; jb->upper_threshold = upper_threshold; jb->wp = 0; @@ -5349,16 +5367,19 @@ jb->state_full = 0; jb->state_empty = 0; jb->bytes_wrote = 0; - jb->samples = (char *)malloc(size*sizeof(char)); + jb->samples = ast_malloc(size*sizeof(char)); if (!jb->samples) { + ast_free(jb); chan_misdn_log(-1,0,"No free Mem for jb->samples\n"); return NULL; } - jb->ok = (char *)malloc(size*sizeof(char)); + jb->ok = ast_malloc(size*sizeof(char)); if (!jb->ok) { + ast_free(jb->samples); + ast_free(jb); chan_misdn_log(-1,0,"No free Mem for jb->ok\n"); return NULL; } @@ -5376,8 +5397,8 @@ { ast_mutex_destroy(&jb->mutexjb); - free(jb->samples); - free(jb); + ast_free(jb->samples); + ast_free(jb); } /* fills the jitterbuffer with len data returns < 0 if there was an Index: channels/chan_skinny.c =================================================================== --- channels/chan_skinny.c (revision 67164) +++ channels/chan_skinny.c (working copy) @@ -2123,7 +2123,7 @@ int speeddialInstance = 1; int y = 0; - if (!(d = ast_calloc(1, sizeof(struct skinny_device)))) { + if (!(d = ast_calloc(1, sizeof(*d)))) { return NULL; } else { ast_copy_string(d->name, cat, sizeof(d->name)); @@ -2135,7 +2135,7 @@ while(v) { if (!strcasecmp(v->name, "host")) { if (ast_get_ip(&d->addr, v->value)) { - free(d); + ast_free(d); return NULL; } } else if (!strcasecmp(v->name, "port")) { @@ -2201,7 +2201,7 @@ } else if (!strcasecmp(v->name, "linelabel")) { ast_copy_string(linelabel, v->value, sizeof(linelabel)); } else if (!strcasecmp(v->name, "speeddial")) { - if (!(sd = ast_calloc(1, sizeof(struct skinny_speeddial)))) { + if (!(sd = ast_calloc(1, sizeof(*sd)))) { return NULL; } else { char *stringp, *exten, *context, *label; @@ -2230,7 +2230,7 @@ d->speeddials = sd; } } else if (!strcasecmp(v->name, "addon")) { - if (!(a = ast_calloc(1, sizeof(struct skinny_addon)))) { + if (!(a = ast_calloc(1, sizeof(*a)))) { return NULL; } else { ast_mutex_init(&a->lock); @@ -2240,7 +2240,7 @@ d->addons = a; } } else if (!strcasecmp(v->name, "trunk") || !strcasecmp(v->name, "line")) { - if (!(l = ast_calloc(1, sizeof(struct skinny_line)))) { + if (!(l = ast_calloc(1, sizeof(*l)))) { return NULL; } else { ast_mutex_init(&l->lock); @@ -2848,7 +2848,7 @@ ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); return NULL; } else { - sub = ast_calloc(1, sizeof(struct skinny_subchannel)); + sub = ast_calloc(1, sizeof(*sub)); if (!sub) { ast_log(LOG_WARNING, "Unable to allocate Skinny subchannel\n"); return NULL; @@ -4248,7 +4248,7 @@ if ((!s->device) && (letohl(req->e) != REGISTER_MESSAGE && letohl(req->e) != ALARM_MESSAGE)) { ast_log(LOG_WARNING, "Client sent message #%d without first registering.\n", req->e); - free(req); + ast_free(req); return 0; } @@ -4396,7 +4396,7 @@ break; } if (res >= 0 && req) - free(req); + ast_free(req); return res; } @@ -4422,7 +4422,7 @@ close(s->fd); } ast_mutex_destroy(&s->lock); - free(s); + ast_free(s); } else { ast_log(LOG_WARNING, "Trying to delete nonexistent session %p?\n", s); } @@ -4519,7 +4519,7 @@ if (letohl(req->e) < 0) { ast_log(LOG_ERROR, "Event Message is NULL from socket %d, This is bad\n", s->fd); - free(req); + ast_free(req); return NULL; } @@ -4894,25 +4894,25 @@ llast = l; l = l->next; ast_mutex_destroy(&llast->lock); - free(llast); + ast_free(llast); } /* Delete all speeddials for this device */ for (sd=d->speeddials;sd;) { sdlast = sd; sd = sd->next; ast_mutex_destroy(&sdlast->lock); - free(sdlast); + ast_free(sdlast); } /* Delete all addons for this device */ for (a=d->addons;a;) { alast = a; a = a->next; ast_mutex_destroy(&alast->lock); - free(alast); + ast_free(alast); } dlast = d; d = d->next; - free(dlast); + ast_free(dlast); } devices=NULL; ast_mutex_unlock(&devicelock); @@ -4997,7 +4997,7 @@ if (slast->fd > -1) close(slast->fd); ast_mutex_destroy(&slast->lock); - free(slast); + ast_free(slast); } sessions = NULL; ast_mutex_unlock(&sessionlock); Index: channels/chan_mgcp.c =================================================================== --- channels/chan_mgcp.c (revision 67164) +++ channels/chan_mgcp.c (working copy) @@ -697,15 +697,18 @@ static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub, char *data, int len, unsigned int seqno) { - struct mgcp_message *msg = ast_malloc(sizeof(*msg) + len); + struct mgcp_message *msg; struct mgcp_message *cur; - struct mgcp_gateway *gw = ((p && p->parent) ? p->parent : NULL); + struct mgcp_gateway *gw; struct timeval tv; + msg = ast_malloc(sizeof(*msg) + len); if (!msg) { return -1; } + gw = ((p && p->parent) ? p->parent : NULL); if (!gw) { + ast_free(msg); return -1; } /* SC Index: channels/chan_local.c =================================================================== --- channels/chan_local.c (revision 67164) +++ channels/chan_local.c (working copy) @@ -178,7 +178,7 @@ return and destroy p. */ ast_mutex_unlock(&p->lock); ast_mutex_destroy(&p->lock); - free(p); + ast_free(p); return -1; } if (!other) { @@ -530,7 +530,7 @@ /* And destroy */ if (!glaredetect) { ast_mutex_destroy(&p->lock); - free(p); + ast_free(p); } return 0; } @@ -577,7 +577,7 @@ if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) { ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context); ast_mutex_destroy(&tmp->lock); - free(tmp); + ast_free(tmp); tmp = NULL; } else { /* Add to list */ Index: channels/chan_gtalk.c =================================================================== --- channels/chan_gtalk.c (revision 67164) +++ channels/chan_gtalk.c (working copy) @@ -257,7 +257,7 @@ static void gtalk_member_destroy(struct gtalk *obj) { - free(obj); + ast_free(obj); } static struct gtalk *find_gtalk(char *name, char *connection) @@ -817,9 +817,9 @@ safeout: if (ours1) - free(ours1); + ast_free(ours1); if (ours2) - free(ours2); + ast_free(ours2); if (iq) iks_delete(iq); if (gtalk) @@ -1036,7 +1036,7 @@ while (candidate) { last = candidate; candidate = candidate->next; - free(last); + ast_free(last); } } @@ -1064,7 +1064,7 @@ if (p->vrtp) ast_rtp_destroy(p->vrtp); gtalk_free_candidates(p->theircandidates); - free(p); + ast_free(p); } Index: channels/iax2-parser.c =================================================================== --- channels/iax2-parser.c (revision 67164) +++ channels/iax2-parser.c (working copy) @@ -922,7 +922,7 @@ prev->next = var; else ies->vars = var; - free(var2); + ast_free(var2); break; } } @@ -1048,14 +1048,14 @@ #if !defined(LOW_MEMORY) if (!fr->cacheable || !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) { - free(fr); + ast_free(fr); return; } fr->direction = 0; AST_LIST_INSERT_HEAD(iax_frames, fr, list); #else - free(fr); + ast_free(fr); #endif } @@ -1066,9 +1066,9 @@ struct iax_frame *cur; while ((cur = AST_LIST_REMOVE_HEAD(frames, list))) - free(cur); + ast_free(cur); - free(frames); + ast_free(frames); } #endif