Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 149593) +++ channels/chan_sip.c (working copy) @@ -476,6 +476,7 @@ time_t last_dnsupdate; /*!< When this was resolved */ enum sip_transport transport; int force; /*!< If it's an outbound proxy, Force use of this outbound proxy for all outbound requests */ + struct sip_peer *refpeer; /* Room for a SRV record chain based on the name */ }; @@ -2614,6 +2615,7 @@ if (sipdebug) ast_debug(1, "OBPROXY: Applying peer OBproxy to this call\n"); append_history(dialog, "OBproxy", "Using peer obproxy %s", peer->outboundproxy->name); + ref_peer(peer, "handing out peer's outboundproxy ref"); return peer->outboundproxy; } if (global_outboundproxy.name[0]) { @@ -4646,6 +4648,10 @@ p->chanvars = NULL; } + if (p->outboundproxy && p->outboundproxy->refpeer) { + unref_peer(p->outboundproxy->refpeer, "dialog does not need peer's outboundproxy anymore"); + } + ast_string_field_free_memory(p); if (p->socket.ser) { @@ -20972,6 +20978,9 @@ } /* Allocate proxy object */ peer->outboundproxy = proxy_allocate(proxyname, port, forceopt); + if (peer->outboundproxy) { + peer->outboundproxy->refpeer = peer; + } } else if (!strcasecmp(v->name, "host")) { if (!strcasecmp(v->value, "dynamic")) { /* They'll register with us */