Skip to content

Commit 2786f7b

Browse files
authored
fix memory leak caused by previous commit (#7)
Previous Commit 25b2b7b. New commit from the master branch 48bcd06
1 parent 7b80a9a commit 2786f7b

File tree

1 file changed

+16
-66
lines changed

1 file changed

+16
-66
lines changed

src/mod/endpoints/mod_sofia/sofia_presence.c

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,69 +3771,36 @@ void sofia_presence_handle_sip_i_subscribe(int status,
37713771
switch_snprintf(exp_delta_str, sizeof(exp_delta_str), "%ld", exp_delta);
37723772

37733773
if (!strcmp("as-feature-event", event)) {
3774-
sip_authorization_t const *authorization = NULL;
3775-
auth_res_t auth_res = AUTH_FORBIDDEN;
37763774
char key[128] = "";
3775+
uint8_t res;
37773776
switch_event_t *v_event = NULL;
37783777

3778+
res = sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, sizeof(key), &v_event, NULL, NULL, NULL);
37793779

3780-
if (sip->sip_authorization) {
3781-
authorization = sip->sip_authorization;
3782-
} else if (sip->sip_proxy_authorization) {
3783-
authorization = sip->sip_proxy_authorization;
3780+
if (v_event) {
3781+
switch_event_destroy(&v_event);
37843782
}
37853783

3786-
if (authorization) {
3787-
char network_ip[80];
3788-
int network_port;
3789-
sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
3790-
auth_res = sofia_reg_parse_auth(profile, authorization, sip, de,
3791-
(char *) sip->sip_request->rq_method_name, key, sizeof(key), network_ip, network_port, &v_event, 0,
3792-
REG_REGISTER, to_user, NULL, NULL, NULL);
3793-
if (v_event) switch_event_destroy(&v_event);
3794-
} else if (sofia_reg_handle_register(nua, profile, nh, sip, de, REG_REGISTER, key, sizeof(key), &v_event, NULL, NULL, NULL)) {
3795-
if (v_event) switch_event_destroy(&v_event);
3796-
goto end;
3797-
}
3798-
3799-
if ((auth_res != AUTH_OK && auth_res != AUTH_RENEWED)) {
3800-
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
3784+
if (res) {
38013785
goto end;
38023786
}
38033787
} else if (sofia_test_pflag(profile, PFLAG_AUTH_SUBSCRIPTIONS)) {
3804-
sip_authorization_t const *authorization = NULL;
3805-
auth_res_t auth_res = AUTH_FORBIDDEN;
38063788
char keybuf[128] = "";
38073789
char *key;
38083790
size_t keylen;
3791+
uint8_t res;
38093792
switch_event_t *v_event = NULL;
38103793

38113794
key = keybuf;
38123795
keylen = sizeof(keybuf);
38133796

3814-
if (sip->sip_authorization) {
3815-
authorization = sip->sip_authorization;
3816-
} else if (sip->sip_proxy_authorization) {
3817-
authorization = sip->sip_proxy_authorization;
3818-
}
3819-
3820-
if (authorization) {
3821-
char network_ip[80];
3822-
int network_port;
3823-
sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
3824-
auth_res = sofia_reg_parse_auth(profile, authorization, sip, de,
3825-
(char *) sip->sip_request->rq_method_name, key, keylen, network_ip, network_port, NULL, 0,
3826-
REG_INVITE, NULL, NULL, NULL, NULL);
3827-
} else if ( sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, (uint32_t)keylen, &v_event, NULL, NULL, NULL)) {
3828-
if (v_event) {
3829-
switch_event_destroy(&v_event);
3830-
}
3797+
res = sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, (uint32_t)keylen, &v_event, NULL, NULL, NULL);
38313798

3832-
goto end;
3799+
if (v_event) {
3800+
switch_event_destroy(&v_event);
38333801
}
38343802

3835-
if ((auth_res != AUTH_OK && auth_res != AUTH_RENEWED)) {
3836-
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
3803+
if (res) {
38373804
goto end;
38383805
}
38393806
}
@@ -4777,39 +4744,22 @@ void sofia_presence_handle_sip_i_message(int status,
47774744
}
47784745

47794746
if (sofia_test_pflag(profile, PFLAG_AUTH_MESSAGES)) {
4780-
sip_authorization_t const *authorization = NULL;
4781-
auth_res_t auth_res = AUTH_FORBIDDEN;
47824747
char keybuf[128] = "";
47834748
char *key;
47844749
size_t keylen;
4750+
uint8_t res;
47854751
switch_event_t *v_event = NULL;
47864752

47874753
key = keybuf;
47884754
keylen = sizeof(keybuf);
47894755

4790-
if (sip->sip_authorization) {
4791-
authorization = sip->sip_authorization;
4792-
} else if (sip->sip_proxy_authorization) {
4793-
authorization = sip->sip_proxy_authorization;
4794-
}
4795-
4796-
if (authorization) {
4797-
char network_ip[80];
4798-
int network_port;
4799-
sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
4800-
auth_res = sofia_reg_parse_auth(profile, authorization, sip, de,
4801-
(char *) sip->sip_request->rq_method_name, key, keylen, network_ip, network_port, NULL, 0,
4802-
REG_INVITE, NULL, NULL, NULL, NULL);
4803-
} else if ( sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, (uint32_t)keylen, &v_event, NULL, NULL, NULL)) {
4804-
if (v_event) {
4805-
switch_event_destroy(&v_event);
4806-
}
4807-
4808-
goto end;
4756+
res = sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, (uint32_t)keylen, &v_event, NULL, NULL, NULL);
4757+
4758+
if (v_event) {
4759+
switch_event_destroy(&v_event);
48094760
}
48104761

4811-
if ((auth_res != AUTH_OK && auth_res != AUTH_RENEWED)) {
4812-
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
4762+
if (res) {
48134763
goto end;
48144764
}
48154765

0 commit comments

Comments
 (0)