Fix defects detected by static analysis tool 68/306268/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 19 Feb 2024 08:37:40 +0000 (17:37 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 19 Feb 2024 09:00:57 +0000 (18:00 +0900)
Change-Id: Ic53d90b9783c0fe2cde0e47b2baca984bae544e6

server/sttd_engine_agent.c
server/sttd_recorder.c

index c06eb8d..2ae3a23 100644 (file)
@@ -98,6 +98,7 @@ int sttd_engine_agent_init(result_callback result_cb, result_time_callback time_
 
        if (0 != sttd_config_get_default_language(&(g_default_language))) {
                SLOG(LOG_WARN, TAG_STTD, "[Engine Agent WARNING] There is No default voice in config");
+               free(g_default_language);
                /* Set default voice */
                g_default_language = strdup("en_US");
        } else {
index 38e2981..5edba52 100644 (file)
@@ -838,17 +838,21 @@ static int stop_recording_with_audio_fw()
 
 int sttd_recorder_stop()
 {
+       // critical section required because this function can be called from stt engine thread context
+       SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section");
+       pthread_mutex_lock(&sttd_audio_in_handle_mutex);
+
        if (STTD_RECORDER_STATE_NONE == g_recorder_state) {
                SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Recorder is not created yet");
+               pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
                return STTD_ERROR_NONE;
        }
 
-       if (STTD_RECORDER_STATE_READY == g_recorder_state)
+       if (STTD_RECORDER_STATE_READY == g_recorder_state) {
+               SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Recorder state is currently READY");
+               pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
                return 0;
-
-       // critical section required because this function can be called from stt engine thread context
-       SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section");
-       pthread_mutex_lock(&sttd_audio_in_handle_mutex);
+       }
 
        /* Check engine id is valid */
        if (NULL == g_recorder) {