Index: asterisk/channels/chan_sip.c =================================================================== --- asterisk/channels/chan_sip.c (revision 7300) +++ asterisk/channels/chan_sip.c (working copy) @@ -2201,19 +2208,16 @@ ast_copy_string(name, fup->username, sizeof(name)); /* Check the list of users */ - u = find_user(name, 1); - if (u) { - inuse = &u->inUse; - call_limit = &u->call_limit; - p = NULL; - } else { - /* Try to find peer */ - if (!p) - p = find_peer(fup->peername, NULL, 1); - if (p) { - inuse = &p->inUse; - call_limit = &p->call_limit; - ast_copy_string(name, fup->peername, sizeof(name)); + p = find_peer(name, NULL, 0); + if (p) { + inuse = &p->inUse; + call_limit = &p->call_limit; + } else if (!u) { + /* Try to find user */ + u = find_user(name, 0); + if (u) { + inuse = &u->inUse; + call_limit = &u->call_limit; } else { if (option_debug > 1) ast_log(LOG_DEBUG, "%s is not a local user, no call limit\n", name); @@ -2236,10 +2241,10 @@ if (*call_limit > 0 ) { if (*inuse >= *call_limit) { ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "u - if (u) + if (p) + ASTOBJ_UNREF(p,sip_destroy_peer); + else ASTOBJ_UNREF(u,sip_destroy_user); - else - ASTOBJ_UNREF(p,sip_destroy_peer); return -1; } } @@ -2251,10 +2257,10 @@ default: ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event); } - if (u) + if (p) + ASTOBJ_UNREF(p,sip_destroy_peer); + else ASTOBJ_UNREF(u,sip_destroy_user); - else - ASTOBJ_UNREF(p,sip_destroy_peer); return 0; }