Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mod_radius_cdr] Coverity CID 1395529 (Resource leak) #2044

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ static switch_status_t my_on_routing(switch_core_session_t *session)

if (channel) {
const char *disable_flag = switch_channel_get_variable(channel, "disable_radius_start");

if (switch_true(disable_flag)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[mod_radius_cdr] Not Sending RADIUS Start\n");

return SWITCH_STATUS_SUCCESS;
}
}
Expand Down Expand Up @@ -250,34 +252,39 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
goto end;
}
}

if (profile->caller_id_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number);
rc_destroy(rad_config);
goto end;
}
}

if (profile->caller_id_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name);
rc_destroy(rad_config);
goto end;
}
}

if (profile->destination_number) {
if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number);
rc_destroy(rad_config);
goto end;
}
}

if (profile->dialplan) {
if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan);
rc_destroy(rad_config);
goto end;
}
}

if (profile->network_addr) {
inet_pton(AF_INET, (void *) profile->network_addr, &framed_addr);
framed_addr = htonl(framed_addr);
Expand All @@ -287,41 +294,47 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
goto end;
}
}

if (profile->rdnis) {
if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis);
rc_destroy(rad_config);
goto end;
}
}

if (profile->context) {
if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context);
rc_destroy(rad_config);
goto end;
}
}

if (profile->ani) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani);
rc_destroy(rad_config);
goto end;
}
}

if (profile->aniii) {
if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii);
rc_destroy(rad_config);
goto end;
}
}

if (profile->source) {
if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source);
rc_destroy(rad_config);
goto end;
}
}

if (callstartdate > 0) {
switch_time_exp_tz(&tm, callstartdate, requested_tm.tm_gmtoff);
switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
Expand Down Expand Up @@ -380,25 +393,33 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
}

if (radius_avpair) {
char *radius_avpair_data_tmp = NULL;

radius_avpair_data = strdup(radius_avpair + (strncmp(radius_avpair, "ARRAY::", 7) ? 0 : 7));
radius_avpair_data_tmp = radius_avpair_data;

do {
delim = strstr(radius_avpair_data, "|:");
delim = strstr(radius_avpair_data_tmp, "|:");

if (delim) {
*delim = '\0';
}

if (rc_avpair_add(rad_config, &send, PW_FS_AVPAIR, (void *) radius_avpair_data, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-AVPair: %s\n", radius_avpair_data);
if (rc_avpair_add(rad_config, &send, PW_FS_AVPAIR, (void *)radius_avpair_data_tmp, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-AVPair: %s\n", radius_avpair_data_tmp);
rc_destroy(rad_config);
switch_safe_free(radius_avpair_data);
goto end;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added Freeswitch-AVPair: %s\n", radius_avpair_data);

switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added Freeswitch-AVPair: %s\n", radius_avpair_data_tmp);

if (delim) {
radius_avpair_data = delim + 2;
radius_avpair_data_tmp = delim + 2;
}
} while (delim);

switch_safe_free(radius_avpair_data);
}

} else {
Expand All @@ -413,11 +434,13 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[mod_radius_cdr] RADIUS Accounting Failed\n");
retval = SWITCH_STATUS_TERM;
}

rc_avpair_free(send);
rc_destroy(rad_config);
end:
switch_xml_free(cdr);
switch_thread_rwlock_unlock(globals.rwlock);

return (retval);
}

Expand Down