[asterisk-commits] tilghman: trunk r66981 - /trunk/channels/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Jun 2 23:10:28 MST 2007
Author: tilghman
Date: Sun Jun 3 01:10:27 2007
New Revision: 66981
URL: http://svn.digium.com/view/asterisk?view=rev&rev=66981
Log:
ast_calloc janitor (Inspired by issue 9860)
Modified:
trunk/channels/chan_features.c
trunk/channels/chan_gtalk.c
trunk/channels/chan_h323.c
trunk/channels/chan_jingle.c
trunk/channels/chan_mgcp.c
trunk/channels/chan_nbs.c
trunk/channels/chan_phone.c
Modified: trunk/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_features.c?view=diff&rev=66981&r1=66980&r2=66981
==============================================================================
--- trunk/channels/chan_features.c (original)
+++ trunk/channels/chan_features.c Sun Jun 3 01:10:27 2007
@@ -387,7 +387,7 @@
ast_hangup(p->subchan);
ast_mutex_unlock(&p->lock);
ast_mutex_destroy(&p->lock);
- free(p);
+ ast_free(p);
return 0;
}
ast_mutex_unlock(&p->lock);
@@ -428,9 +428,8 @@
ast_log(LOG_NOTICE, "Unable to allocate subchannel '%s/%s'\n", tech, dest);
return NULL;
}
- tmp = malloc(sizeof(struct feature_pvt));
+ tmp = ast_calloc(1, sizeof(*tmp));
if (tmp) {
- memset(tmp, 0, sizeof(struct feature_pvt));
for (x=0;x<3;x++)
init_sub(tmp->subs + x);
ast_mutex_init(&tmp->lock);
@@ -461,7 +460,7 @@
/* figure out what you want the name to be */
for (x=1;x<4;x++) {
if (b2)
- free(b2);
+ ast_free(b2);
asprintf(&b2, "%s/%s-%d", p->tech, p->dest, x);
for (y=0;y<3;y++) {
if (y == index)
@@ -475,7 +474,7 @@
tmp = ast_channel_alloc(0, state, 0,0, "", "", "", 0, "Feature/%s", b2);
/* free up the name, it was copied into the channel name */
if (b2)
- free(b2);
+ ast_free(b2);
if (!tmp) {
ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
return NULL;
@@ -566,7 +565,7 @@
if (p->owner)
ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
AST_LIST_REMOVE_CURRENT(&features, list);
- free(p);
+ ast_free(p);
}
AST_LIST_TRAVERSE_SAFE_END
AST_LIST_UNLOCK(&features);
Modified: trunk/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_gtalk.c?view=diff&rev=66981&r1=66980&r2=66981
==============================================================================
--- trunk/channels/chan_gtalk.c (original)
+++ trunk/channels/chan_gtalk.c Sun Jun 3 01:10:27 2007
@@ -881,7 +881,7 @@
tmp->parent = client;
if (!tmp->rtp) {
ast_log(LOG_WARNING, "Out of RTP sessions?\n");
- free(tmp);
+ ast_free(tmp);
return NULL;
}
@@ -1600,8 +1600,7 @@
{
char *name, *type, *preference, *protocol;
struct gtalk_candidate *res;
- res = malloc(sizeof(struct gtalk_candidate));
- memset(res, 0, sizeof(struct gtalk_candidate));
+ res = ast_calloc(1, sizeof(*res));
if (args)
name = args;
if ((args = strchr(args, ','))) {
@@ -1758,8 +1757,7 @@
while (cat) {
if (strcasecmp(cat, "general")) {
var = ast_variable_browse(cfg, cat);
- member = (struct gtalk *) malloc(sizeof(struct gtalk));
- memset(member, 0, sizeof(struct gtalk));
+ member = ast_calloc(1, sizeof(*member));
ASTOBJ_INIT(member);
ASTOBJ_WRLOCK(member);
if (!strcasecmp(cat, "guest")) {
Modified: trunk/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_h323.c?view=diff&rev=66981&r1=66980&r2=66981
==============================================================================
--- trunk/channels/chan_h323.c (original)
+++ trunk/channels/chan_h323.c Sun Jun 3 01:10:27 2007
@@ -288,7 +288,7 @@
{
if (h323debug)
ast_log(LOG_DEBUG, "Destroying alias '%s'\n", alias->name);
- free(alias);
+ ast_free(alias);
}
static void oh323_destroy_user(struct oh323_user *user)
@@ -296,7 +296,7 @@
if (h323debug)
ast_log(LOG_DEBUG, "Destroying user '%s'\n", user->name);
ast_free_ha(user->ha);
- free(user);
+ ast_free(user);
}
static void oh323_destroy_peer(struct oh323_peer *peer)
@@ -304,7 +304,7 @@
if (h323debug)
ast_log(LOG_DEBUG, "Destroying peer '%s'\n", peer->name);
ast_free_ha(peer->ha);
- free(peer);
+ ast_free(peer);
}
static int oh323_simulate_dtmf_end(void *data)
@@ -419,35 +419,35 @@
static void cleanup_call_details(call_details_t *cd)
{
if (cd->call_token) {
- free(cd->call_token);
+ ast_free(cd->call_token);
cd->call_token = NULL;
}
if (cd->call_source_aliases) {
- free(cd->call_source_aliases);
+ ast_free(cd->call_source_aliases);
cd->call_source_aliases = NULL;
}
if (cd->call_dest_alias) {
- free(cd->call_dest_alias);
+ ast_free(cd->call_dest_alias);
cd->call_dest_alias = NULL;
}
if (cd->call_source_name) {
- free(cd->call_source_name);
+ ast_free(cd->call_source_name);
cd->call_source_name = NULL;
}
if (cd->call_source_e164) {
- free(cd->call_source_e164);
+ ast_free(cd->call_source_e164);
cd->call_source_e164 = NULL;
}
if (cd->call_dest_e164) {
- free(cd->call_dest_e164);
+ ast_free(cd->call_dest_e164);
cd->call_dest_e164 = NULL;
}
if (cd->sourceIp) {
- free(cd->sourceIp);
+ ast_free(cd->sourceIp);
cd->sourceIp = NULL;
}
if (cd->redirect_number) {
- free(cd->redirect_number);
+ ast_free(cd->redirect_number);
cd->redirect_number = NULL;
}
}
@@ -496,7 +496,7 @@
} else {
ast_mutex_unlock(&pvt->lock);
ast_mutex_destroy(&pvt->lock);
- free(pvt);
+ ast_free(pvt);
}
}
@@ -540,7 +540,7 @@
ast_mutex_unlock(&pvt->lock);
h323_send_tone(token, digit);
if (token) {
- free(token);
+ ast_free(token);
}
} else
ast_mutex_unlock(&pvt->lock);
@@ -579,7 +579,7 @@
ast_mutex_unlock(&pvt->lock);
h323_send_tone(token, ' ');
if (token) {
- free(token);
+ ast_free(token);
}
}
oh323_update_info(c);
@@ -684,7 +684,7 @@
ast_mutex_unlock(&pvt->lock);
res = h323_answering_call(token, 0);
if (token)
- free(token);
+ ast_free(token);
oh323_update_info(c);
if (c->_state != AST_STATE_UP) {
@@ -746,7 +746,7 @@
if (h323_clear_call(call_token, q931cause)) {
ast_log(LOG_WARNING, "ClearCall failed.\n");
}
- free(call_token);
+ ast_free(call_token);
ast_mutex_lock(&pvt->lock);
}
}
@@ -939,7 +939,7 @@
if (h323debug)
ast_log(LOG_DEBUG, "OH323: Indicated %d on %s, res=%d\n", condition, token, res);
if (token)
- free(token);
+ ast_free(token);
oh323_update_info(c);
return res;
@@ -1113,23 +1113,22 @@
{
struct oh323_pvt *pvt;
- pvt = (struct oh323_pvt *) malloc(sizeof(struct oh323_pvt));
+ pvt = ast_calloc(1, sizeof(*pvt));
if (!pvt) {
ast_log(LOG_ERROR, "Couldn't allocate private structure. This is bad\n");
return NULL;
}
- memset(pvt, 0, sizeof(struct oh323_pvt));
pvt->cd.redirect_reason = -1;
pvt->cd.transfer_capability = -1;
/* Ensure the call token is allocated for outgoing call */
if (!callid) {
if ((pvt->cd).call_token == NULL) {
- (pvt->cd).call_token = (char *)malloc(128);
+ (pvt->cd).call_token = ast_calloc(1, 128);
}
if (!pvt->cd.call_token) {
ast_log(LOG_ERROR, "Not enough memory to alocate call token\n");
ast_rtp_destroy(pvt->rtp);
- free(pvt);
+ ast_free(pvt);
return NULL;
}
memset((char *)(pvt->cd).call_token, 0, 128);
@@ -1210,7 +1209,7 @@
if (alias)
found++;
else {
- if (!(alias = (struct oh323_alias *)calloc(1, sizeof(*alias))))
+ if (!(alias = ast_calloc(1, sizeof(*alias))))
return NULL;
ASTOBJ_INIT(alias);
}
@@ -1379,7 +1378,7 @@
if (user)
found++;
else {
- if (!(user = (struct oh323_user *)calloc(1, sizeof(*user))))
+ if (!(user = ast_calloc(1, sizeof(*user))))
return NULL;
ASTOBJ_INIT(user);
}
@@ -1496,7 +1495,7 @@
if (peer)
found++;
else {
- if (!(peer = (struct oh323_peer*)calloc(1, sizeof(*peer))))
+ if (!(peer = ast_calloc(1, sizeof(*peer))))
return NULL;
ASTOBJ_INIT(peer);
}
@@ -1908,14 +1907,14 @@
struct sockaddr_in us;
struct rtp_info *info;
- info = (struct rtp_info *)malloc(sizeof(struct rtp_info));
+ info = ast_calloc(1, sizeof(*info));
if (!info) {
ast_log(LOG_ERROR, "Unable to allocated info structure, this is very bad\n");
return NULL;
}
pvt = find_call_locked(call_reference, token);
if (!pvt) {
- free(info);
+ ast_free(info);
ast_log(LOG_ERROR, "Unable to find call %s(%d)\n", token, call_reference);
return NULL;
}
@@ -1923,7 +1922,7 @@
__oh323_rtp_create(pvt);
if (!pvt->rtp) {
ast_mutex_unlock(&pvt->lock);
- free(info);
+ ast_free(info);
ast_log(LOG_ERROR, "No RTP stream is available for call %s (%d)", token, call_reference);
return NULL;
}
@@ -3337,7 +3336,7 @@
p = p->next;
/* free associated memory */
ast_mutex_destroy(&pl->lock);
- free(pl);
+ ast_free(pl);
}
iflist = NULL;
ast_mutex_unlock(&iflock);
Modified: trunk/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_jingle.c?view=diff&rev=66981&r1=66980&r2=66981
==============================================================================
--- trunk/channels/chan_jingle.c (original)
+++ trunk/channels/chan_jingle.c Sun Jun 3 01:10:27 2007
@@ -238,7 +238,7 @@
static void jingle_member_destroy(struct jingle *obj)
{
- free(obj);
+ ast_free(obj);
}
static struct jingle *find_jingle(char *name, char *connection)
@@ -691,9 +691,9 @@
safeout:
if (ours1)
- free(ours1);
+ ast_free(ours1);
if (ours2)
- free(ours2);
+ ast_free(ours2);
if (iq)
iks_delete(iq);
if (jingle)
@@ -750,7 +750,7 @@
tmp->parent = client;
if (!tmp->rtp) {
ast_log(LOG_WARNING, "Out of RTP sessions?\n");
- free(tmp);
+ ast_free(tmp);
return NULL;
}
ast_copy_string(tmp->exten, "s", sizeof(tmp->exten));
@@ -883,7 +883,7 @@
while (candidate) {
last = candidate;
candidate = candidate->next;
- free(last);
+ ast_free(last);
}
}
@@ -911,7 +911,7 @@
if (p->vrtp)
ast_rtp_destroy(p->vrtp);
jingle_free_candidates(p->theircandidates);
- free(p);
+ ast_free(p);
}
@@ -1465,8 +1465,7 @@
{
char *name, *type, *preference, *protocol;
struct jingle_candidate *res;
- res = malloc(sizeof(struct jingle_candidate));
- memset(res, 0, sizeof(struct jingle_candidate));
+ res = ast_calloc(1, sizeof(*res));
if (args)
name = args;
if ((args = strchr(args, ','))) {
@@ -1615,8 +1614,7 @@
while (cat) {
if (strcasecmp(cat, "general")) {
var = ast_variable_browse(cfg, cat);
- member = (struct jingle *) malloc(sizeof(struct jingle));
- memset(member, 0, sizeof(struct jingle));
+ member = ast_calloc(1, sizeof(*member));
ASTOBJ_INIT(member);
ASTOBJ_WRLOCK(member);
if (!strcasecmp(cat, "guest")) {
Modified: trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_mgcp.c?view=diff&rev=66981&r1=66980&r2=66981
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Sun Jun 3 01:10:27 2007
@@ -584,7 +584,7 @@
while (q) {
cur = q;
q = q->next;
- free(cur);
+ ast_free(cur);
}
}
@@ -686,7 +686,7 @@
/* time-out transaction */
handle_response(cur->owner_ep, cur->owner_sub, 406, cur->seqno, NULL);
exq = exq->next;
- free(cur);
+ ast_free(cur);
}
return res;
@@ -696,7 +696,7 @@
static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
char *data, int len, unsigned int seqno)
{
- struct mgcp_message *msg = malloc(sizeof(struct mgcp_message) + len);
+ struct mgcp_message *msg = ast_malloc(sizeof(*msg) + len);
struct mgcp_message *cur;
struct mgcp_gateway *gw = ((p && p->parent) ? p->parent : NULL);
struct timeval tv;
@@ -783,7 +783,7 @@
/* delete pending cx cmds */
while (q) {
r = q->next;
- free(q);
+ ast_free(q);
q = r;
}
*queue = NULL;
@@ -810,13 +810,13 @@
}
}
- r = (struct mgcp_request *) malloc (sizeof(struct mgcp_request));
+ r = ast_malloc(sizeof(*r));
if (!r) {
ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n");
ast_mutex_unlock(l);
return -1;
}
- memcpy(r, req, sizeof(struct mgcp_request));
+ memcpy(r, req, sizeof(*r));
if (!(*queue)) {
if (mgcpdebug) {
@@ -2026,10 +2026,9 @@
struct mgcp_response *mgr;
respprep(&resp, p, msg, req, msgrest);
- mgr = malloc(sizeof(struct mgcp_response) + resp.len + 1);
+ mgr = ast_calloc(1, sizeof(*mgr) + resp.len + 1);
if (mgr) {
/* Store MGCP response in case we have to retransmit */
- memset(mgr, 0, sizeof(struct mgcp_response));
sscanf(req->identifier, "%d", &mgr->seqno);
time(&mgr->whensent);
mgr->len = resp.len;
@@ -2384,27 +2383,27 @@
if (p) {
ast_mutex_lock(&p->rqnt_queue_lock);
- for (q = p->rqnt_queue; q; t = q->next, free(q), q=t);
+ for (q = p->rqnt_queue; q; t = q->next, ast_free(q), q=t);
p->rqnt_queue = NULL;
ast_mutex_unlock(&p->rqnt_queue_lock);
ast_mutex_lock(&p->cmd_queue_lock);
- for (q = p->cmd_queue; q; t = q->next, free(q), q=t);
+ for (q = p->cmd_queue; q; t = q->next, ast_free(q), q=t);
p->cmd_queue = NULL;
ast_mutex_unlock(&p->cmd_queue_lock);
ast_mutex_lock(&p->sub->cx_queue_lock);
- for (q = p->sub->cx_queue; q; t = q->next, free(q), q=t);
+ for (q = p->sub->cx_queue; q; t = q->next, ast_free(q), q=t);
p->sub->cx_queue = NULL;
ast_mutex_unlock(&p->sub->cx_queue_lock);
ast_mutex_lock(&p->sub->next->cx_queue_lock);
- for (q = p->sub->next->cx_queue; q; t = q->next, free(q), q=t);
+ for (q = p->sub->next->cx_queue; q; t = q->next, ast_free(q), q=t);
p->sub->next->cx_queue = NULL;
ast_mutex_unlock(&p->sub->next->cx_queue_lock);
} else if (sub) {
ast_mutex_lock(&sub->cx_queue_lock);
- for (q = sub->cx_queue; q; t = q->next, free(q), q=t);
+ for (q = sub->cx_queue; q; t = q->next, ast_free(q), q=t);
sub->cx_queue = NULL;
ast_mutex_unlock(&sub->cx_queue_lock);
}
@@ -2607,7 +2606,7 @@
}
}
- free(req);
+ ast_free(req);
}
static void start_rtp(struct mgcp_subchannel *sub)
@@ -3313,7 +3312,7 @@
prev->next = next;
else
sub->parent->parent->responses = next;
- free(cur);
+ ast_free(cur);
} else {
if (seqno == cur->seqno)
answer = cur;
@@ -3390,7 +3389,7 @@
ast_mutex_unlock(&gw->msgs_lock);
if (cur) {
handle_response(cur->owner_ep, cur->owner_sub, result, ident, &req);
- free(cur);
+ ast_free(cur);
return 1;
}
@@ -3614,11 +3613,10 @@
}
if (!gw)
- gw = malloc(sizeof(struct mgcp_gateway));
+ gw = ast_calloc(1, sizeof(*gw));
if (gw) {
if (!gw_reload) {
- memset(gw, 0, sizeof(struct mgcp_gateway));
gw->expire = -1;
gw->retransid = -1; /* SC */
ast_mutex_init(&gw->msgs_lock);
@@ -3647,7 +3645,7 @@
if (ast_get_ip(&gw->addr, v->value)) {
if (!gw_reload) {
ast_mutex_destroy(&gw->msgs_lock);
- free(gw);
+ ast_free(gw);
}
return NULL;
}
@@ -3656,7 +3654,7 @@
if (ast_get_ip(&gw->defaddr, v->value)) {
if (!gw_reload) {
ast_mutex_destroy(&gw->msgs_lock);
- free(gw);
+ ast_free(gw);
}
return NULL;
}
@@ -3741,7 +3739,7 @@
if (!e) {
/* Allocate wildcard endpoint */
- e = malloc(sizeof(struct mgcp_endpoint));
+ e = ast_calloc(1, sizeof(*e));
ep_reload = 0;
}
@@ -3797,10 +3795,9 @@
if (!ep_reload) {
/*snprintf(txident, sizeof(txident), "%08lx", ast_random());*/
for (i = 0; i < MAX_SUBS; i++) {
- sub = malloc(sizeof(struct mgcp_subchannel));
+ sub = ast_calloc(1, sizeof(*sub));
if (sub) {
ast_verbose(VERBOSE_PREFIX_3 "Allocating subchannel '%d' on %s@%s\n", i, e->name, gw->name);
- memset(sub, 0, sizeof(struct mgcp_subchannel));
ast_mutex_init(&sub->lock);
ast_mutex_init(&sub->cx_queue_lock);
sub->parent = e;
@@ -3846,13 +3843,12 @@
}
if (!e) {
- e = malloc(sizeof(struct mgcp_endpoint));
+ e = ast_calloc(1, sizeof(*e));
ep_reload = 0;
}
if (e) {
if (!ep_reload) {
- memset(e, 0, sizeof(struct mgcp_endpoint));
ast_mutex_init(&e->lock);
ast_mutex_init(&e->rqnt_queue_lock);
ast_mutex_init(&e->cmd_queue_lock);
@@ -3905,7 +3901,7 @@
for (i = 0, sub = NULL; i < MAX_SUBS; i++) {
if (!ep_reload) {
- sub = malloc(sizeof(struct mgcp_subchannel));
+ sub = ast_calloc(1, sizeof(*sub));
} else {
if (!sub)
sub = e->sub;
@@ -3916,7 +3912,6 @@
if (sub) {
if (!ep_reload) {
ast_verbose(VERBOSE_PREFIX_3 "Allocating subchannel '%d' on %s@%s\n", i, e->name, gw->name);
- memset(sub, 0, sizeof(struct mgcp_subchannel));
ast_mutex_init(&sub->lock);
ast_mutex_init(&sub->cx_queue_lock);
ast_copy_string(sub->magic, MGCP_SUBCHANNEL_MAGIC, sizeof(sub->magic));
@@ -3957,7 +3952,7 @@
ast_log(LOG_WARNING, "Gateway '%s' lacks IP address and isn't dynamic\n", gw->name);
if (!gw_reload) {
ast_mutex_destroy(&gw->msgs_lock);
- free(gw);
+ ast_free(gw);
}
return NULL;
}
@@ -4041,7 +4036,7 @@
sub = sub->next;
ast_mutex_destroy(&s->lock);
ast_mutex_destroy(&s->cx_queue_lock);
- free(s);
+ ast_free(s);
}
if (e->mwi_event_sub)
@@ -4050,7 +4045,7 @@
ast_mutex_destroy(&e->lock);
ast_mutex_destroy(&e->rqnt_queue_lock);
ast_mutex_destroy(&e->cmd_queue_lock);
- free(e);
+ ast_free(e);
}
static void destroy_gateway(struct mgcp_gateway *g)
@@ -4060,7 +4055,7 @@
dump_queue(g, NULL);
- free (g);
+ ast_free(g);
}
static void prune_gateways(void)
Modified: trunk/channels/chan_nbs.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_nbs.c?view=diff&rev=66981&r1=66980&r2=66981
==============================================================================
--- trunk/channels/chan_nbs.c (original)
+++ trunk/channels/chan_nbs.c Sun Jun 3 01:10:27 2007
@@ -122,7 +122,7 @@
if (p->nbs)
nbs_delstream(p->nbs);
ast_module_user_remove(p->u);
- free(p);
+ ast_free(p);
}
static struct nbs_pvt *nbs_alloc(void *data)
@@ -138,9 +138,8 @@
opts++;
} else
opts = "";
- p = malloc(sizeof(struct nbs_pvt));
+ p = ast_calloc(1, sizeof(*p));
if (p) {
- memset(p, 0, sizeof(struct nbs_pvt));
if (!ast_strlen_zero(opts)) {
if (strchr(opts, 'm'))
flags |= NBS_FLAG_MUTE;
@@ -157,7 +156,7 @@
p->nbs = nbs_newstream("asterisk", stream, flags);
if (!p->nbs) {
ast_log(LOG_WARNING, "Unable to allocate new NBS stream '%s' with flags %d\n", stream, flags);
- free(p);
+ ast_free(p);
p = NULL;
} else {
/* Set for 8000 hz mono, 640 samples */
Modified: trunk/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_phone.c?view=diff&rev=66981&r1=66980&r2=66981
==============================================================================
--- trunk/channels/chan_phone.c (original)
+++ trunk/channels/chan_phone.c Sun Jun 3 01:10:27 2007
@@ -1179,12 +1179,12 @@
struct phone_pvt *tmp;
int flags;
- tmp = malloc(sizeof(struct phone_pvt));
+ tmp = ast_calloc(1, sizeof(*tmp));
if (tmp) {
tmp->fd = open(iface, O_RDWR);
if (tmp->fd < 0) {
ast_log(LOG_WARNING, "Unable to open '%s'\n", iface);
- free(tmp);
+ ast_free(tmp);
return NULL;
}
if (mode == MODE_FXO) {
@@ -1344,7 +1344,7 @@
pl = p;
p = p->next;
/* Free associated memory */
- free(pl);
+ ast_free(pl);
}
iflist = NULL;
ast_mutex_unlock(&iflock);
More information about the asterisk-commits
mailing list