diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 9921e30bd1..151e135ede 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -15940,7 +15940,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str if (peer) { /* Already in the list, remove it and it will be added back (or FREE'd) */ - found++; + found = 1; if (!(peer->objflags & ASTOBJ_FLAG_MARKED)) firstpass = 0; } else { @@ -16009,10 +16009,9 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str ast_log(LOG_WARNING, "You can't have a dynamic outbound proxy, you big silly head at line %d.\n", v->lineno); } else { /* They'll register with us */ - ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC); - if (!found) { - /* Initialize stuff iff we're not found, otherwise - we keep going with what we had */ + if (!found || !ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) { + /* Initialize stuff if this is a new peer, or if it used to be + * non-dynamic before the reload. */ memset(&peer->addr.sin_addr, 0, 4); if (peer->addr.sin_port) { /* If we've already got a port, make it the default rather than absolute */ @@ -16020,6 +16019,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str peer->addr.sin_port = 0; } } + ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC); } } else { /* Non-dynamic. Make sure we become that way if we're not */