[Asterisk-cvs] asterisk/channels chan_agent.c,1.74,1.75 chan_h323.c,1.59,1.60 chan_iax.c,1.59,1.60 chan_iax2.c,1.155,1.156 chan_local.c,1.29,1.30 chan_mgcp.c,1.54,1.55 chan_sip.c,1.420,1.421 chan_skinny.c,1.46,1.47 chan_vpb.c,1.26,1.27 chan_zap.c,1.278,1.279
markster at lists.digium.com
markster at lists.digium.com
Tue Jun 22 13:56:19 CDT 2004
Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv21170/channels
Modified Files:
chan_agent.c chan_h323.c chan_iax.c chan_iax2.c chan_local.c
chan_mgcp.c chan_sip.c chan_skinny.c chan_vpb.c chan_zap.c
Log Message:
Merge major BSD mutex and symbol conflict patches (bug #1816) (link patch still pending)
Index: chan_agent.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_agent.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- chan_agent.c 9 Jun 2004 01:45:07 -0000 1.74
+++ chan_agent.c 22 Jun 2004 17:42:13 -0000 1.75
@@ -213,8 +213,8 @@
if (p) {
memset(p, 0, sizeof(struct agent_pvt));
strncpy(p->agent, tmp, sizeof(p->agent) -1);
- ast_mutex_init( &p->lock );
- ast_mutex_init( &p->app_lock );
+ ast_mutex_init(&p->lock);
+ ast_mutex_init(&p->app_lock);
p->owning_app = (pthread_t) -1;
p->app_sleep_cond = 1;
p->group = group;
@@ -252,8 +252,11 @@
ast_mutex_unlock(&p->app_lock);
if (chan)
ast_channel_free(chan);
- if (p->dead)
+ if (p->dead) {
+ ast_mutex_destroy(&p->lock);
+ ast_mutex_destroy(&p->app_lock);
free(p);
+ }
return 0;
}
@@ -571,6 +574,8 @@
kill it later */
p->abouttograb = 0;
} else if (p->dead) {
+ ast_mutex_destroy(&p->lock);
+ ast_mutex_destroy(&p->app_lock);
free(p);
} else {
if (p->chan) {
@@ -844,6 +849,8 @@
/* Destroy if appropriate */
if (!p->owner) {
if (!p->chan) {
+ ast_mutex_destroy(&p->lock);
+ ast_mutex_destroy(&p->app_lock);
free(p);
} else {
/* Cause them to hang up */
@@ -1425,8 +1432,11 @@
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Agent '%s' logged out\n", p->agent);
/* If there is no owner, go ahead and kill it now */
- if (p->dead && !p->owner)
+ if (p->dead && !p->owner) {
+ ast_mutex_destroy(&p->lock);
+ ast_mutex_destroy(&p->app_lock);
free(p);
+ }
}
else {
ast_mutex_unlock(&p->lock);
Index: chan_h323.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_h323.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- chan_h323.c 15 Jun 2004 20:56:05 -0000 1.59
+++ chan_h323.c 22 Jun 2004 17:42:13 -0000 1.60
@@ -55,7 +55,8 @@
#include <fcntl.h>
#include <netdb.h>
#include <sys/signal.h>
-#ifdef __OpenBSD__
+#include <sys/param.h>
+#if defined(BSD)
#include <netinet/in_systm.h>
#ifndef IPTOS_MINCOST
#define IPTOS_MINCOST 0x02
@@ -186,8 +187,10 @@
}
if (!cur) {
ast_log(LOG_WARNING, "%p is not in list?!?! \n", cur);
- } else
+ } else {
+ ast_mutex_destroy(&p->lock);
free(p);
+ }
}
static void oh323_destroy(struct oh323_pvt *p)
@@ -1840,11 +1843,14 @@
set_rtp_peer: oh323_set_rtp_peer,
};
-
int load_module()
{
int res;
+ ast_mutex_init(&userl.lock);
+ ast_mutex_init(&peerl.lock);
+ ast_mutex_init(&aliasl.lock);
+
res = reload_config();
if (res) {
@@ -1948,6 +1954,7 @@
pl = p;
p = p->next;
/* free associated memory */
+ ast_mutex_destroy(&pl->lock);
free(pl);
}
iflist = NULL;
Index: chan_iax.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- chan_iax.c 9 Jun 2004 01:45:07 -0000 1.59
+++ chan_iax.c 22 Jun 2004 17:42:13 -0000 1.60
@@ -447,7 +447,7 @@
struct iax_dpcache *peer; /* For linking in peers */
} *dpcache;
-static ast_mutex_t dpcache_lock;
+AST_MUTEX_DEFINE_STATIC(dpcache_lock);
#ifdef DEBUG_SUPPORT
static void showframe(struct ast_iax_frame *f, struct ast_iax_full_hdr *fhi, int rx, struct sockaddr_in *sin)
@@ -5369,6 +5369,12 @@
int unload_module()
{
+ int x;
+ for (x=0;x<AST_IAX_MAX_CALLS;x++)
+ ast_mutex_destroy(&iaxsl[x]);
+ ast_mutex_destroy(&iaxq.lock);
+ ast_mutex_destroy(&userl.lock);
+ ast_mutex_destroy(&peerl.lock);
return __unload_module();
}
@@ -5403,7 +5409,6 @@
ast_mutex_init(&iaxq.lock);
ast_mutex_init(&userl.lock);
ast_mutex_init(&peerl.lock);
- ast_mutex_init(&dpcache_lock);
ast_cli_register(&cli_show_users);
ast_cli_register(&cli_show_channels);
Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -d -r1.155 -r1.156
--- chan_iax2.c 16 Jun 2004 13:52:50 -0000 1.155
+++ chan_iax2.c 22 Jun 2004 17:42:13 -0000 1.156
@@ -507,7 +507,7 @@
struct iax2_dpcache *peer; /* For linking in peers */
} *dpcache;
-static ast_mutex_t dpcache_lock;
+AST_MUTEX_DEFINE_STATIC(dpcache_lock);
static void iax_debug_output(const char *data)
{
@@ -4434,6 +4434,7 @@
ast_log(LOG_DEBUG, "Dropping unused iax2 trunk peer '%s:%d'\n", inet_ntoa(drop->addr.sin_addr), ntohs(drop->addr.sin_port));
free(drop->trunkdata);
ast_mutex_unlock(&drop->lock);
+ ast_mutex_destroy(&drop->lock);
free(drop);
}
@@ -6820,6 +6821,10 @@
int unload_module()
{
+ ast_mutex_destroy(&iaxq.lock);
+ ast_mutex_destroy(&userl.lock);
+ ast_mutex_destroy(&peerl.lock);
+ ast_mutex_destroy(&waresl.lock);
return __unload_module();
}
@@ -6867,6 +6872,7 @@
ast_mutex_init(&iaxq.lock);
ast_mutex_init(&userl.lock);
ast_mutex_init(&peerl.lock);
+ ast_mutex_init(&waresl.lock);
ast_cli_register(&cli_show_users);
ast_cli_register(&cli_show_channels);
Index: chan_local.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_local.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- chan_local.c 22 Jun 2004 04:54:52 -0000 1.29
+++ chan_local.c 22 Jun 2004 17:42:13 -0000 1.30
@@ -87,6 +87,7 @@
/* We had a glare on the hangup. Forget all this business,
return and destroy p. */
ast_mutex_unlock(&p->lock);
+ ast_mutex_destroy(&p->lock);
free(p);
return -1;
}
@@ -271,6 +272,7 @@
prev->next = cur->next;
else
locals = cur->next;
+ ast_mutex_destroy(cur);
free(cur);
break;
}
@@ -324,8 +326,10 @@
}
ast_mutex_unlock(&locallock);
/* And destroy */
- if (!glaredetect)
+ if (!glaredetect) {
+ ast_mutex_destroy(&p->lock);
free(p);
+ }
return 0;
}
if (p->chan && !p->launchedpbx)
@@ -366,6 +370,7 @@
tmp->reqformat = format;
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->context, tmp->exten);
+ ast_mutex_destroy(&tmp->lock);
free(tmp);
tmp = NULL;
} else {
Index: chan_mgcp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_mgcp.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- chan_mgcp.c 9 Jun 2004 01:45:07 -0000 1.54
+++ chan_mgcp.c 22 Jun 2004 17:42:13 -0000 1.55
@@ -3423,15 +3423,19 @@
gw->expire = -1;
gw->dynamic = 0;
if (ast_get_ip(&gw->addr, v->value)) {
- if (!gw_reload)
+ if (!gw_reload) {
+ ast_mutex_destroy(&gw->msgs_lock);
free(gw);
+ }
return NULL;
}
}
} else if (!strcasecmp(v->name, "defaultip")) {
if (ast_get_ip(&gw->defaddr, v->value)) {
- if (!gw_reload)
+ if (!gw_reload) {
+ ast_mutex_destroy(&gw->msgs_lock);
free(gw);
+ }
return NULL;
}
} else if (!strcasecmp(v->name, "permit") ||
@@ -3501,15 +3505,17 @@
}
if (!e) {
+ /* Allocate wildcard endpoint */
e = malloc(sizeof(struct mgcp_endpoint));
ep_reload = 0;
}
- /* Allocate wildcard endpoint */
- e = malloc(sizeof(struct mgcp_endpoint));
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);
strncpy(e->name, v->value, sizeof(e->name) - 1);
e->needaudit = 1;
}
@@ -3545,6 +3551,8 @@
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;
sub->id = i;
snprintf(sub->txident, sizeof(sub->txident), "%08x", rand());
@@ -3594,6 +3602,9 @@
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);
strncpy(e->name, v->value, sizeof(e->name) - 1);
e->needaudit = 1;
}
@@ -3633,8 +3644,6 @@
/* ASSUME we're onhook */
e->hookstate = MGCP_ONHOOK;
snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08x", rand());
- ast_mutex_init(&e->rqnt_queue_lock);
- ast_mutex_init(&e->cmd_queue_lock);
}
for (i = 0, sub = NULL; i < MAX_SUBS; i++) {
@@ -3652,13 +3661,14 @@
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);
strncpy(sub->magic, MGCP_SUBCHANNEL_MAGIC, sizeof(sub->magic) - 1);
sub->parent = e;
sub->id = i;
snprintf(sub->txident, sizeof(sub->txident), "%08x", rand());
sub->cxmode = MGCP_CX_INACTIVE;
sub->next = e->sub;
- ast_mutex_init(&sub->cx_queue_lock);
e->sub = sub;
}
sub->nat = nat;
@@ -3690,8 +3700,10 @@
}
if (!ntohl(gw->addr.sin_addr.s_addr) && !gw->dynamic) {
ast_log(LOG_WARNING, "Gateway '%s' lacks IP address and isn't dynamic\n", gw->name);
- if (!gw_reload)
+ if (!gw_reload) {
+ ast_mutex_destroy(&gw->msgs_lock);
free(gw);
+ }
return NULL;
}
if (gw->defaddr.sin_addr.s_addr && !ntohs(gw->defaddr.sin_port))
@@ -3803,8 +3815,13 @@
for (i = 0; (i < MAX_SUBS) && sub; i++) {
s = sub;
sub = sub->next;
+ ast_mutex_destroy(&s->lock);
+ ast_mutex_destroy(&s->cx_queue_lock);
free(s);
}
+ ast_mutex_destroy(&e->lock);
+ ast_mutex_destroy(&e->rqnt_queue_lock);
+ ast_mutex_destroy(&e->cmd_queue_lock);
free(e);
}
@@ -4132,6 +4149,9 @@
pl = p;
p = p->next;
/* Free associated memory */
+ ast_mutex_destroy(&pl->lock);
+ ast_mutex_destroy(&pl->rqnt_queue_lock);
+ ast_mutex_destroy(&pl->cmd_queue_lock);
free(pl);
}
iflist = NULL;
Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.420
retrieving revision 1.421
diff -u -d -r1.420 -r1.421
--- chan_sip.c 21 Jun 2004 16:52:04 -0000 1.420
+++ chan_sip.c 22 Jun 2004 17:42:13 -0000 1.421
@@ -2042,11 +2042,11 @@
struct sip_pvt *p;
p = malloc(sizeof(struct sip_pvt));
- ast_mutex_init(&p->lock);
if (!p)
return NULL;
/* Keep track of stuff */
memset(p, 0, sizeof(struct sip_pvt));
+ ast_mutex_init(&p->lock);
p->initid = -1;
p->autokillid = -1;
p->stateid = -1;
@@ -8326,6 +8326,7 @@
pl = p;
p = p->next;
/* Free associated memory */
+ ast_mutex_destroy(&pl->lock);
free(pl);
}
iflist = NULL;
@@ -8338,6 +8339,9 @@
if (localaddr) {
ast_free_ha(localaddr);
}
+ ast_mutex_destroy(&userl.lock);
+ ast_mutex_destroy(&peerl.lock);
+ ast_mutex_destroy(®l.lock);
return 0;
}
Index: chan_skinny.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_skinny.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- chan_skinny.c 14 Jun 2004 21:18:52 -0000 1.46
+++ chan_skinny.c 22 Jun 2004 17:42:13 -0000 1.47
@@ -1104,6 +1104,7 @@
l = malloc(sizeof(struct skinny_line));;
if (l) {
memset(l, 0, sizeof(struct skinny_line));
+ ast_mutex_init(&l->lock);
strncpy(l->name, v->value, sizeof(l->name) - 1);
/* XXX Should we check for uniqueness?? XXX */
@@ -1145,6 +1146,7 @@
if (sub) {
ast_verbose(VERBOSE_PREFIX_3 "Allocating Skinny subchannel '%d' on %s@%s\n", i, l->name, d->name);
memset(sub, 0, sizeof(struct skinny_subchannel));
+ ast_mutex_init(&sub->lock);
sub->parent = l;
/* Make a call*ID */
sub->callid = callnums;
@@ -2262,6 +2264,7 @@
sessions = cur->next;
if (s->fd > -1)
close(s->fd);
+ ast_mutex_destroy(&s->lock);
free(s);
} else
ast_log(LOG_WARNING, "Trying to delete non-existant session %p?\n", s);
@@ -2662,10 +2665,12 @@
for (sub=l->sub;sub;) {
slast = sub;
sub = sub->next;
+ ast_mutex_destroy(&slast->lock);
free(slast);
}
llast = l;
l = l->next;
+ ast_mutex_destroy(&llast->lock);
free(llast);
}
dlast = d;
@@ -2758,6 +2763,7 @@
pl = p;
p = p->next;
/* Free associated memory */
+ ast_mutex_destroy(&pl->lock);
free(pl);
}
iflist = NULL;
Index: chan_vpb.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_vpb.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- chan_vpb.c 9 Jun 2004 01:45:08 -0000 1.26
+++ chan_vpb.c 22 Jun 2004 17:42:13 -0000 1.27
@@ -279,8 +279,6 @@
bridges[i].fo = fo;
bridges[i].c0 = c0;
bridges[i].c1 = c1;
- ast_mutex_init(&bridges[i].lock);
- pthread_cond_init(&bridges[i].cond, NULL);
}
} ast_mutex_unlock(&bridge_lock);
@@ -356,8 +354,6 @@
ast_mutex_lock(&bridge_lock); {
bridges[i].inuse = 0;
- ast_mutex_destroy(&bridges[i].lock);
- pthread_cond_destroy(&bridges[i].cond);
} ast_mutex_unlock(&bridge_lock);
p0->bridge = NULL;
@@ -975,8 +971,13 @@
bridges = (vpb_bridge_t *)malloc(max_bridges * sizeof(vpb_bridge_t) );
if(!bridges)
ast_log(LOG_ERROR, "Failed to initialize bridges\n");
- else
+ else {
memset(bridges,0,max_bridges * sizeof(vpb_bridge_t));
+ for(int i = 0; i < max_bridges; i++ ) {
+ ast_mutex_init(&bridges[i].lock);
+ pthread_cond_init(&bridges[i].cond, NULL);
+ }
+ }
}
if(!echo_cancel) {
if (model==vpb_model_v4pci) {
@@ -1062,6 +1063,7 @@
tmp->vpb_model = vpb_model_v4pci;
}
+ ast_mutex_init(&tmp->owner_lock);
ast_mutex_init(&tmp->lock);
ast_mutex_init(&tmp->record_lock);
ast_mutex_init(&tmp->play_lock);
@@ -2080,6 +2082,7 @@
p = iflist;
ast_mutex_destroy(&p->lock);
pthread_cancel(p->readthread);
+ ast_mutex_destroy(&p->owner_lock);
ast_mutex_destroy(&p->record_lock);
ast_mutex_destroy(&p->play_lock);
ast_mutex_destroy(&p->play_dtmf_lock);
@@ -2098,6 +2101,10 @@
memset(bridges, 0, sizeof bridges);
} ast_mutex_unlock(&bridge_lock);
ast_mutex_destroy(&bridge_lock);
+ for(int i = 0; i < max_bridges; i++ ) {
+ ast_mutex_destroy(&bridges[i].lock);
+ pthread_cond_destroy(&bridges[i].cond, NULL);
+ }
free(bridges);
return 0;
Index: chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.278
retrieving revision 1.279
diff -u -d -r1.278 -r1.279
--- chan_zap.c 21 Jun 2004 03:37:13 -0000 1.278
+++ chan_zap.c 22 Jun 2004 17:42:13 -0000 1.279
@@ -1756,6 +1756,14 @@
return 0;
}
+static void destroy_zt_pvt(struct zt_pvt **pvt)
+{
+ struct zt_pvt *p = *pvt;
+ ast_mutex_destroy(&p->lock);
+ free(p);
+ *pvt = NULL;
+}
+
static int destroy_channel(struct zt_pvt *prev, struct zt_pvt *cur, int now)
{
int owned = 0;
@@ -1788,7 +1796,7 @@
if (cur->subs[SUB_REAL].zfd > -1) {
zt_close(cur->subs[SUB_REAL].zfd);
}
- free(cur);
+ destroy_zt_pvt(&cur);
}
} else {
if (prev) {
@@ -1807,7 +1815,7 @@
if (cur->subs[SUB_REAL].zfd > -1) {
zt_close(cur->subs[SUB_REAL].zfd);
}
- free(cur);
+ destroy_zt_pvt(&cur);
}
return 0;
}
@@ -5751,10 +5759,11 @@
tmp = (struct zt_pvt*)malloc(sizeof(struct zt_pvt));
if (!tmp) {
ast_log(LOG_ERROR, "MALLOC FAILED\n");
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
memset(tmp, 0, sizeof(struct zt_pvt));
+ ast_mutex_init(&tmp->lock);
ifcount++;
for (x=0;x<3;x++)
tmp->subs[x].zfd = -1;
@@ -5811,20 +5820,19 @@
/* Allocate a zapata structure */
if (tmp->subs[SUB_REAL].zfd < 0) {
ast_log(LOG_ERROR, "Unable to open channel %d: %s\nhere = %d, tmp->channel = %d, channel = %d\n", channel, strerror(errno), here, tmp->channel, channel);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
memset(&p, 0, sizeof(p));
res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_GET_PARAMS, &p);
if (res < 0) {
ast_log(LOG_ERROR, "Unable to get parameters\n");
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (p.sigtype != (signalling & 0x3ffff)) {
ast_log(LOG_ERROR, "Signalling requested is %s but line is in %s signalling\n", sig2str(signalling), sig2str(p.sigtype));
- free(tmp);
- tmp = NULL;
+ destroy_zt_pvt(&tmp);
return tmp;
}
if (here) {
@@ -5855,18 +5863,18 @@
offset = 0;
if ((signalling == SIG_PRI) && ioctl(tmp->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &offset)) {
ast_log(LOG_ERROR, "Unable to set clear mode on clear channel %d of span %d: %s\n", channel, p.spanno, strerror(errno));
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (span >= NUM_SPANS) {
ast_log(LOG_ERROR, "Channel %d does not lie on a span I know of (%d)\n", channel, span);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
} else {
si.spanno = 0;
if (ioctl(tmp->subs[SUB_REAL].zfd,ZT_SPANSTAT,&si) == -1) {
ast_log(LOG_ERROR, "Unable to get span status: %s\n", strerror(errno));
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
/* Store the logical span first based upon the real span */
@@ -5874,7 +5882,7 @@
pri_resolve_span(&span, channel, (channel - p.chanpos), &si);
if (span < 0) {
ast_log(LOG_WARNING, "Channel %d: Unable to find locate channel/trunk group!\n", channel);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (signalling == SIG_PRI)
@@ -5895,43 +5903,43 @@
if (!matchesdchan) {
if (pris[span].nodetype && (pris[span].nodetype != pritype)) {
ast_log(LOG_ERROR, "Span %d is already a %s node\n", span + 1, pri_node2str(pris[span].nodetype));
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (pris[span].switchtype && (pris[span].switchtype != myswitchtype)) {
ast_log(LOG_ERROR, "Span %d is already a %s switch\n", span + 1, pri_switch2str(pris[span].switchtype));
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if ((pris[span].dialplan) && (pris[span].dialplan != dialplan)) {
ast_log(LOG_ERROR, "Span %d is already a %s dialing plan\n", span + 1, pri_plan2str(pris[span].dialplan));
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (!ast_strlen_zero(pris[span].idledial) && strcmp(pris[span].idledial, idledial)) {
ast_log(LOG_ERROR, "Span %d already has idledial '%s'.\n", span + 1, idledial);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (!ast_strlen_zero(pris[span].idleext) && strcmp(pris[span].idleext, idleext)) {
ast_log(LOG_ERROR, "Span %d already has idleext '%s'.\n", span + 1, idleext);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (pris[span].minunused && (pris[span].minunused != minunused)) {
ast_log(LOG_ERROR, "Span %d already has minunused of %d.\n", span + 1, minunused);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (pris[span].minidle && (pris[span].minidle != minidle)) {
ast_log(LOG_ERROR, "Span %d already has minidle of %d.\n", span + 1, minidle);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (pris[span].numchans >= MAX_CHANNELS) {
ast_log(LOG_ERROR, "Unable to add channel %d: Too many channels in trunk group %d!\n", channel,
pris[span].trunkgroup);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
pris[span].nodetype = pritype;
@@ -5949,7 +5957,7 @@
tmp->call = NULL;
} else {
ast_log(LOG_ERROR, "Channel %d is reserved for D-channel.\n", offset);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
}
@@ -5968,7 +5976,7 @@
if (!tmp->r2) {
ast_log(LOG_WARNING, "Unable to create r2 call :(\n");
zt_close(tmp->subs[SUB_REAL].zfd);
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
} else {
@@ -6021,7 +6029,7 @@
res = ioctl(tmp->subs[SUB_REAL].zfd, ZT_SET_PARAMS, &p);
if (res < 0) {
ast_log(LOG_ERROR, "Unable to set parameters\n");
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
}
@@ -6081,7 +6089,6 @@
tmp->propconfno = -1;
}
tmp->transfer = transfer;
- ast_mutex_init(&tmp->lock);
strncpy(tmp->defcontext,context,sizeof(tmp->defcontext)-1);
strncpy(tmp->language, language, sizeof(tmp->language)-1);
strncpy(tmp->musicclass, musicclass, sizeof(tmp->musicclass)-1);
@@ -6117,7 +6124,7 @@
memset(&si, 0, sizeof(si));
if (ioctl(tmp->subs[SUB_REAL].zfd,ZT_SPANSTAT,&si) == -1) {
ast_log(LOG_ERROR, "Unable to get span status: %s\n", strerror(errno));
- free(tmp);
+ destroy_zt_pvt(&tmp);
return NULL;
}
if (si.alarms) tmp->inalarm = 1;
@@ -6222,11 +6229,12 @@
p = malloc(sizeof(struct zt_pvt));
if (p) {
memcpy(p, src, sizeof(struct zt_pvt));
+ ast_mutex_init(&p->lock);
p->subs[SUB_REAL].zfd = zt_open("/dev/zap/pseudo");
/* Allocate a zapata structure */
if (p->subs[SUB_REAL].zfd < 0) {
ast_log(LOG_ERROR, "Unable to dup channel: %s\n", strerror(errno));
- free(p);
+ destroy_zt_pvt(&p);
return NULL;
}
res = ioctl(p->subs[SUB_REAL].zfd, ZT_GET_BUFINFO, &bi);
@@ -8280,8 +8288,8 @@
p = p->next;
x++;
/* Free associated memory */
- if(p)
- free(pl);
+ if(pl)
+ destroy_zt_pvt(&pl);
ast_verbose(VERBOSE_PREFIX_3 "Unregistered channel %d\n", x);
}
iflist = NULL;
@@ -8302,6 +8310,11 @@
int unload_module()
{
+#ifdef ZAPATA_PRI
+ int y;
+ for (y=0;y<NUM_SPANS;y++)
+ ast_mutex_destroy(&pris[y].lock);
+#endif
return __unload_module();
}
@@ -8922,6 +8935,7 @@
int y,i;
memset(pris, 0, sizeof(pris));
for (y=0;y<NUM_SPANS;y++) {
+ ast_mutex_init(&pris[y].lock);
pris[y].offset = -1;
pris[y].master = AST_PTHREADT_NULL;
for (i=0;i<NUM_DCHANS;i++)
@@ -9028,9 +9042,13 @@
#if 0
#ifdef ZAPATA_PRI
- memset(pris, 0, sizeof(pris));
for (y=0;y<NUM_SPANS;y++)
+ ast_mutex_destroy(&pris[y]->lock);
+ memset(pris, 0, sizeof(pris));
+ for (y=0;y<NUM_SPANS;y++) {
+ ast_mutex_init(&pris[y]->lock);
pris[y].fd = -1;
+ }
#endif
#endif /* 0 */
More information about the svn-commits
mailing list