[asterisk-commits] rizzo: branch rizzo/astobj2 r47409 -
/team/rizzo/astobj2/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Nov 9 21:17:31 MST 2006
Author: rizzo
Date: Thu Nov 9 22:17:30 2006
New Revision: 47409
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47409
Log:
more refcount cleaning.
make sip_destroy return NULL, it is useful for simplifying the code.
There is some extra sip_destroy now...
Modified:
team/rizzo/astobj2/channels/chan_sip.c
Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=47409&r1=47408&r2=47409
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Thu Nov 9 22:17:30 2006
@@ -82,7 +82,7 @@
* the sip_hangup() function
*/
-#define USE_AO2 // enable to use astobj2
+// #define USE_AO2 // enable to use astobj2
#include "asterisk.h"
@@ -1312,7 +1312,7 @@
static int __sip_autodestruct(void *data);
static void sip_scheddestroy(struct sip_pvt *p, int ms);
static void sip_cancel_destroy(struct sip_pvt *p);
-static void sip_destroy(struct sip_pvt *p);
+static struct sip_pvt * sip_destroy(struct sip_pvt *p);
static struct sip_pvt *__sip_destroy(struct sip_pvt *p);
static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod, int reset);
static void __sip_pretend_ack(struct sip_pvt *p);
@@ -1376,7 +1376,6 @@
static void *do_monitor(void *data);
static int restart_monitor(void);
static int sip_send_mwi_to_peer(struct sip_peer *peer);
-static void sip_destroy(struct sip_pvt *p);
static int sip_addrcmp(char *name, struct sockaddr_in *sin); /* Support for peer matching */
static int sip_refer_allocate(struct sip_pvt *p);
static void ast_quiet_chan(struct ast_channel *chan);
@@ -2532,10 +2531,10 @@
/* Delete it, it needs to disappear */
if (peer->peer_pvt)
- sip_destroy(peer->peer_pvt);
+ peer->peer_pvt = sip_destroy(peer->peer_pvt);
if (peer->mwi_pvt) /* We have an active subscription, delete it */
- sip_destroy(peer->mwi_pvt);
+ peer->mwi_pvt = sip_destroy(peer->mwi_pvt);
if (peer->chanvars) {
ast_variables_destroy(peer->chanvars);
@@ -3029,7 +3028,7 @@
reg->register_pvt->registry = NULL;
if (option_debug > 2)
ast_log(LOG_DEBUG, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
- sip_destroy(reg->register_pvt);
+ reg->register_pvt = sip_destroy(reg->register_pvt);
}
if (reg->expire > -1)
ast_sched_del(sched, reg->expire);
@@ -3038,7 +3037,6 @@
ast_string_field_free_pools(reg);
regobjs--;
free(reg);
-
}
/*!
@@ -3282,12 +3280,13 @@
}
/*! \brief Destroy SIP call structure */
-static void sip_destroy(struct sip_pvt *p)
+static struct sip_pvt *sip_destroy(struct sip_pvt *p)
{
if (option_debug > 2)
ast_log(LOG_DEBUG, "Destroying SIP dialog %s\n", p->callid);
sip_pvt_unlink(p);
__sip_destroy(p);
+ return NULL;
}
/*! \brief Convert SIP hangup causes to Asterisk hangup causes */
@@ -7277,13 +7276,16 @@
if (p) {
/* Unlink us, destroy old call. Locking is not relevant here because all this happens
in the single SIP manager thread. */
+ /* clear register_pvt to prevent unref_registry from killing the session.
+ * the actual destruction is done down in sip_destroy().
+ */
+ r->register_pvt = NULL;
if (p->registry)
unref_registry(p->registry);
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
/* Pretend to ACK anything just in case */
__sip_pretend_ack(p); /* XXX we need p locked, not sure we have */
- r->register_pvt = NULL; /* reference goes away down */
- sip_destroy(p);
+ sip_destroy(p); /* reference goes away */
}
/* If we have a limit, stop registration and give up */
if (global_regattempts_max && (r->regattempts > global_regattempts_max)) {
@@ -8981,7 +8983,7 @@
ast_copy_string(referdata->referred_by, "", sizeof(referdata->referred_by));
ast_copy_string(referdata->refer_contact, "", sizeof(referdata->refer_contact));
if (referdata->refer_pvt) /* XXX or sip_destroy() ? */
- referdata->refer_pvt = pvt_unref(referdata->refer_pvt);
+ referdata->refer_pvt = sip_destroy(referdata->refer_pvt);
/* Set new context */
ast_string_field_set(p, context, transfer_context);
return 0;
@@ -11257,6 +11259,7 @@
ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]);
transmit_sip_request(p, &req);
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
+ pvt_unref(p);
}
return RESULT_SUCCESS;
@@ -12202,8 +12205,7 @@
p->registry->regattempts = global_regattempts_max+1;
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
if (r->register_pvt) /* XXX are we sure about destroy ? */
- sip_destroy(r->register_pvt);
- r->register_pvt = NULL;
+ r->register_pvt = sip_destroy(r->register_pvt);
ast_sched_del(sched, r->timeout);
break;
case 407: /* Proxy auth */
@@ -12218,8 +12220,7 @@
ast_sched_del(sched, r->timeout);
r->timeout = -1;
if (r->register_pvt) { /* XXX are we sure about destroy ? */
- sip_destroy(r->register_pvt);
- r->register_pvt = NULL;
+ r->register_pvt = sip_destroy(r->register_pvt);
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
}
if (r->expiry > max_expiry) {
@@ -12238,8 +12239,7 @@
p->registry->regattempts = global_regattempts_max+1;
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
if (r->register_pvt) /* XXX are we sure about destroy ? */
- sip_destroy(r->register_pvt);
- r->register_pvt = NULL;
+ r->register_pvt = sip_destroy(r->register_pvt);
ast_sched_del(sched, r->timeout);
break;
case 200: /* 200 OK */
@@ -12262,8 +12262,7 @@
}
r->timeout=-1;
if (r->register_pvt) /* XXX are we sure about destroy ? */
- sip_destroy(r->register_pvt);
- r->register_pvt = NULL;
+ r->register_pvt = sip_destroy(r->register_pvt);
p->registry = NULL;
/* Let this one hang around until we have all the responses */
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
@@ -14585,9 +14584,13 @@
}
p->subscribed = MWI_NOTIFICATION;
- if (authpeer->mwi_pvt && authpeer->mwi_pvt != p) /* Destroy old PVT if this is a new one */
+ if (authpeer->mwi_pvt) {
/* We only allow one subscription per peer */
- sip_destroy(authpeer->mwi_pvt);
+ if (authpeer->mwi_pvt != p) /* Destroy old PVT if this is a new one */
+ sip_destroy(authpeer->mwi_pvt);
+ else
+ pvt_unref(authpeer->mwi_pvt);
+ }
authpeer->mwi_pvt = pvt_ref(p); /* Link from peer to pvt */
p->relatedpeer = authpeer; /* Link from pvt to peer */
/* Do not release authpeer here */
@@ -15341,8 +15344,7 @@
manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1);
}
if (peer->peer_pvt)
- sip_destroy(peer->peer_pvt);
- peer->peer_pvt = NULL;
+ peer->peer_pvt = sip_destroy(peer->peer_pvt);
peer->lastms = -1;
ast_device_state_changed("SIP/%s", peer->name);
/* Try again quickly */
@@ -15365,13 +15367,13 @@
peer->lastms = 0;
peer->pokeexpire = -1;
if (peer->peer_pvt) /* XXX or sip_destroy() ? */
- peer->peer_pvt = pvt_unref(peer->peer_pvt);
+ peer->peer_pvt = sip_destroy(peer->peer_pvt);
return 0;
}
if (peer->peer_pvt) {
if (sipdebug)
ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n");
- sip_destroy(peer->peer_pvt);
+ peer->peer_pvt = sip_destroy(peer->peer_pvt);
}
if (!(p = peer->peer_pvt = sip_alloc(NULL, NULL, 0, SIP_OPTIONS)))
return -1;
@@ -15563,9 +15565,12 @@
p->prefcodec = oldformat; /* Format for this call */
sip_pvt_lock(p);
tmpc = sip_new(p, AST_STATE_DOWN, host); /* Place the call */
+ /* XXX who keeps the reference ? */
sip_pvt_unlock(p);
if (!tmpc)
sip_destroy(p);
+ else
+ pvt_unref(p);
ast_update_use_count();
restart_monitor();
return tmpc;
@@ -17318,8 +17323,7 @@
if (option_debug > 2)
ast_log(LOG_DEBUG, "Destroying active SIP dialog for registry %s@%s\n", iterator->username, iterator->hostname);
/* This will also remove references to the registry */
- sip_destroy(iterator->register_pvt);
- iterator->register_pvt = NULL;
+ iterator->register_pvt = sip_destroy(iterator->register_pvt);
}
ASTOBJ_UNLOCK(iterator);
} while(0));
More information about the asterisk-commits
mailing list