diff --git a/src/ctrlm_utils.cpp b/src/ctrlm_utils.cpp index 947e6618..edac08c1 100644 --- a/src/ctrlm_utils.cpp +++ b/src/ctrlm_utils.cpp @@ -293,21 +293,39 @@ void ctrlm_print_controller_status(const char *prefix, ctrlm_controller_status_t ERR_CHK(safec_rc); } else { time_binding_str[0] = '\0'; - strftime(time_binding_str, 20, "%F %T", localtime((time_t *)&status->time_binding)); + struct tm time_info; + time_t time_binding = (time_t)status->time_binding; + if(NULL == localtime_r(&time_binding, &time_info)) { + XLOGD_ERROR("Failed to convert time_binding to local time"); + } else { + strftime(time_binding_str, 20, "%F %T", &time_info); + } } if(status->time_last_key == 0) { safec_rc = strcpy_s(time_last_key_str, sizeof(time_last_key_str), "NEVER"); ERR_CHK(safec_rc); } else { time_last_key_str[0] = '\0'; - strftime(time_last_key_str, 20, "%F %T", localtime((time_t *)&status->time_last_key)); + struct tm time_info; + time_t time_last_key = (time_t)status->time_last_key; + if(NULL == localtime_r(&time_last_key, &time_info)) { + XLOGD_ERROR("Failed to convert time_last_key to local time"); + } else { + strftime(time_last_key_str, 20, "%F %T", &time_info); + } } if(status->time_battery_update == 0) { safec_rc = strcpy_s(time_battery_update_str, sizeof(time_battery_update_str), "NEVER"); ERR_CHK(safec_rc); } else { time_battery_update_str[0] = '\0'; - strftime(time_battery_update_str, 20, "%F %T", localtime((time_t *)&status->time_battery_update)); + struct tm time_info; + time_t time_battery_update = (time_t)status->time_battery_update; + if(NULL == localtime_r(&time_battery_update, &time_info)) { + XLOGD_ERROR("Failed to convert time_battery_update to local time"); + } else { + strftime(time_battery_update_str, 20, "%F %T", &time_info); + } } const xlog_args_t xlog_args_info = {.options = XLOG_OPTS_DEFAULT, .color = XLOG_COLOR_NONE, .function = prefix, .line = XLOG_LINE_NONE, .level = XLOG_LEVEL_INFO, .id = XLOG_MODULE_ID, .size_max = XLOG_BUF_SIZE_DEFAULT}; diff --git a/src/database/ctrlm_database.cpp b/src/database/ctrlm_database.cpp index 61b801fa..4b8dfdfd 100644 --- a/src/database/ctrlm_database.cpp +++ b/src/database/ctrlm_database.cpp @@ -1540,7 +1540,8 @@ void ctrlm_db_print() { ctrlm_db_rf4ce_read_validation_type(*it_network, *it_controller, &validation_type); ctrlm_db_rf4ce_read_time_binding(*it_network, *it_controller, &time_binding); - const tm* loc_time = localtime(&time_binding); + struct tm time_info; + const tm* loc_time = localtime_r(&time_binding, &time_info); if (loc_time != 0) { strftime(time_str, 40, "%x - %I:%M:%S %p", loc_time); } diff --git a/src/factory/ctrlmf_audio_capture.cpp b/src/factory/ctrlmf_audio_capture.cpp index 0d76772a..a4e77580 100644 --- a/src/factory/ctrlmf_audio_capture.cpp +++ b/src/factory/ctrlmf_audio_capture.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,7 @@ static ctrlmf_audio_cap_global_t g_audio_cap; bool ctrlmf_audio_capture_init(uint32_t audio_frame_size, bool *has_local_mic_tap) { - g_audio_cap.obj_ctrlm = new Iarm::ControlManager::ctrlm_iarm_client_control_manager_t; + g_audio_cap.obj_ctrlm = new(std::nothrow) Iarm::ControlManager::ctrlm_iarm_client_control_manager_t; if(g_audio_cap.obj_ctrlm == NULL) { XLOGD_ERROR("out of memory"); diff --git a/src/factory/ctrlmf_audio_playback.cpp b/src/factory/ctrlmf_audio_playback.cpp index 498e3caa..13fd9f3c 100644 --- a/src/factory/ctrlmf_audio_playback.cpp +++ b/src/factory/ctrlmf_audio_playback.cpp @@ -8,7 +8,7 @@ #include #include #include - +#include typedef struct { Thunder::SystemAudioPlayer::ctrlm_thunder_plugin_system_audio_player_t *obj_sap; @@ -20,7 +20,7 @@ static void ctrlmf_audio_playback_event_handler(system_audio_player_event_t even static ctrlmf_audio_play_global_t g_audio_play; bool ctrlmf_audio_playback_init(void) { - g_audio_play.obj_sap = new Thunder::SystemAudioPlayer::ctrlm_thunder_plugin_system_audio_player_t; + g_audio_play.obj_sap = new(std::nothrow) Thunder::SystemAudioPlayer::ctrlm_thunder_plugin_system_audio_player_t; if(g_audio_play.obj_sap == NULL) { XLOGD_ERROR("out of memory"); diff --git a/src/factory/ctrlmf_mic_test.cpp b/src/factory/ctrlmf_mic_test.cpp index 1db94630..8d9e2287 100644 --- a/src/factory/ctrlmf_mic_test.cpp +++ b/src/factory/ctrlmf_mic_test.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include #include @@ -306,12 +308,20 @@ void ctrlmf_mic_test_audio_export(const char *filename, ctrlmf_audio_frame_t aud uint32_t pcm_data_size = frame_qty * SAMPLES_PER_FRAME * channel_qty * sample_size; errno = 0; - FILE *fh = fopen(filename, "w"); - if(NULL == fh) { + int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR); + if(fd < 0) { int errsv = errno; XLOGD_ERROR("Unable to open file <%s> <%s>", filename, strerror(errsv)); return; } + errno = 0; + FILE *fh = fdopen(fd, "w"); + if(NULL == fh) { + int errsv = errno; + XLOGD_ERROR("Unable to fdopen file <%s> <%s>", filename, strerror(errsv)); + close(fd); + return; + } XLOGD_INFO("write wave header - %u-bit PCM %u hz %u chans %lu bytes", sample_size * 8, sample_rate, channel_qty, pcm_data_size); diff --git a/src/rf4ce/ctrlm_rf4ce_controller.cpp b/src/rf4ce/ctrlm_rf4ce_controller.cpp index c298ab9e..8ae0119d 100644 --- a/src/rf4ce/ctrlm_rf4ce_controller.cpp +++ b/src/rf4ce/ctrlm_rf4ce_controller.cpp @@ -2783,7 +2783,12 @@ void ctrlm_obj_controller_rf4ce_t::log_binding_for_telemetry() { } else { time_binding_str[0] = '\0'; time_t time_binding = this->time_binding_get(); - strftime(time_binding_str, 20, "%F %T", localtime((time_t *)&time_binding)); + struct tm time_info; + if(NULL == localtime_r(&time_binding, &time_info)) { + XLOGD_ERROR("Failed to convert time_binding to local time"); + } else { + strftime(time_binding_str, 20, "%F %T", &time_info); + } } XLOGD_INFO("Model <%s>, Binding <%s>, Remote Bound (%u,%u), Time <%s>", product_name_->to_string().c_str(), ctrlm_rcu_binding_type_str(binding_type_), network_id_get(), controller_id_get(), time_binding_str); ctrlm_update_last_key_info(controller_id, CTRLM_KEY_SOURCE_RF, 0, product_name_->to_string().c_str(), false, true); @@ -2794,7 +2799,12 @@ void ctrlm_obj_controller_rf4ce_t::log_unbinding_for_telemetry() { time_t time_unbinding = time(NULL); time_unbinding_str[0] = '\0'; - strftime(time_unbinding_str, 20, "%F %T", localtime((time_t *)&time_unbinding)); + struct tm time_info; + if(NULL == localtime_r(&time_unbinding, &time_info)) { + XLOGD_ERROR("Failed to convert time_unbinding to local time"); + } else { + strftime(time_unbinding_str, 20, "%F %T", &time_info); + } XLOGD_INFO("Model <%s>, Remote Unbound (%u,%u), Time <%s>", product_name_->to_string().c_str(), network_id_get(), controller_id_get(), time_unbinding_str); } diff --git a/src/rf4ce/ctrlm_rf4ce_network.cpp b/src/rf4ce/ctrlm_rf4ce_network.cpp index 01e41b95..8dce469e 100644 --- a/src/rf4ce/ctrlm_rf4ce_network.cpp +++ b/src/rf4ce/ctrlm_rf4ce_network.cpp @@ -28,6 +28,7 @@ #include #include #endif +#include #include #include #include @@ -2249,7 +2250,7 @@ json_t *ctrlm_obj_network_rf4ce_t::xconf_export_controllers() { } else { // we dont have type in map so add it; - controller_type_details_t *new_type = new controller_type_details_t(); + controller_type_details_t *new_type = new(std::nothrow) controller_type_details_t(); if(new_type==NULL){ XLOGD_ERROR("error on allocating.. aborting" ); // if we could not malloc memory then we need to free our current mallocs and get out @@ -3987,7 +3988,7 @@ vector *ctrlm_obj_network_rf4ce_t::de } if(sessions == NULL) { - sessions = new vector; + sessions = new(std::nothrow) vector; if(sessions == NULL) { XLOGD_ERROR("out of memory"); break; diff --git a/src/thunder/ctrlm_thunder_plugin_powermanager.cpp b/src/thunder/ctrlm_thunder_plugin_powermanager.cpp index e84fa983..74bce0cc 100755 --- a/src/thunder/ctrlm_thunder_plugin_powermanager.cpp +++ b/src/thunder/ctrlm_thunder_plugin_powermanager.cpp @@ -37,7 +37,10 @@ ctrlm_thunder_plugin_powermanager_t::ctrlm_thunder_plugin_powermanager_t() : ctr } ctrlm_thunder_plugin_powermanager_t::~ctrlm_thunder_plugin_powermanager_t() { - free(instance); + sem_destroy(&this->semaphore); + if(instance == this) { + instance = NULL; + } } ctrlm_thunder_plugin_powermanager_t *ctrlm_thunder_plugin_powermanager_t::get_instance() { diff --git a/src/voice/ctrlm_voice_obj.cpp b/src/voice/ctrlm_voice_obj.cpp index c50aa886..c3d4e981 100644 --- a/src/voice/ctrlm_voice_obj.cpp +++ b/src/voice/ctrlm_voice_obj.cpp @@ -1299,11 +1299,9 @@ ctrlm_voice_session_response_status_t ctrlm_voice_t::voice_session_req(ctrlm_net request_params.type = XRSR_SESSION_REQUEST_TYPE_AUDIO_FILE; request_params.value.audio_file.path = audio_file_in; - xrsr_audio_format_t xrsr_format; + xrsr_audio_format_t xrsr_format = { .type = XRSR_AUDIO_FORMAT_PCM}; if(format.type == CTRLM_VOICE_FORMAT_OPUS) { xrsr_format.type = XRSR_AUDIO_FORMAT_OPUS; - } else { - xrsr_format.type = XRSR_AUDIO_FORMAT_PCM; } if (false == xrsr_session_request(voice_device_to_xrsr(device_type), dst_index, xrsr_format, request_params, uuid, false, false)) {