Skip to content

Commit

Permalink
mid_registrar: Fix mishandled corner-cases
Browse files Browse the repository at this point in the history
    * avoid extraneous "udomain unlock" operations on some error cases

(cherry picked from commit b3bdf7c)
(cherry picked from commit e3d7b59)
  • Loading branch information
liviuchircu committed Nov 26, 2019
1 parent 198a6db commit f32fa99
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modules/mid_registrar/save.c
Expand Up @@ -2283,7 +2283,7 @@ int mid_reg_save(struct sip_msg *msg, char *dom, char *flags_gp,
str flags_str = { NULL, 0 }, to_uri = { NULL, 0 };
struct save_ctx sctx;
struct hdr_field *path;
int rc = -1, st;
int rc = -1, st, unlock_udomain = 0;

if (msg->REQ_METHOD != METHOD_REGISTER) {
LM_ERR("ignoring non-REGISTER SIP request (%d)\n", msg->REQ_METHOD);
Expand Down Expand Up @@ -2356,6 +2356,7 @@ int mid_reg_save(struct sip_msg *msg, char *dom, char *flags_gp,
return prepare_forward(msg, ud, &sctx);

update_act_time();
unlock_udomain = 1;
ul_api.lock_udomain(ud, &sctx.aor);

if (ul_api.get_urecord(ud, &sctx.aor, &rec) != 0) {
Expand All @@ -2380,8 +2381,8 @@ int mid_reg_save(struct sip_msg *msg, char *dom, char *flags_gp,
if (rec != NULL && rec->contacts != NULL)
build_contact(rec->contacts, msg);

/* no contacts need updating on the far end registrar */
ul_api.unlock_udomain(ud, &sctx.aor);
if (unlock_udomain)
ul_api.unlock_udomain(ud, &sctx.aor);

/* quick SIP reply */
if (!(sctx.flags & REG_SAVE_NOREPLY_FLAG))
Expand All @@ -2394,7 +2395,8 @@ int mid_reg_save(struct sip_msg *msg, char *dom, char *flags_gp,
return prepare_forward(msg, ud, &sctx);

out_error:
ul_api.unlock_udomain(ud, &sctx.aor);
if (unlock_udomain)
ul_api.unlock_udomain(ud, &sctx.aor);
if (!(sctx.flags & REG_SAVE_NOREPLY_FLAG))
send_reply(msg, sctx.flags);
return -1;
Expand Down

0 comments on commit f32fa99

Please sign in to comment.