Add critical section to avoid thread safety issue 89/149189/2
authorWonnam Jang <wn.jang@samsung.com>
Tue, 12 Sep 2017 01:32:13 +0000 (10:32 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Wed, 13 Sep 2017 06:41:33 +0000 (15:41 +0900)
Change-Id: Ie5fc64abd2285aae4d69e2594108dc4eefe30d66
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
server/sttd_recorder.c

index 16202d0..b83cc47 100644 (file)
@@ -593,9 +593,14 @@ int sttd_recorder_stop()
        if (STTD_RECORDER_STATE_READY == g_recorder_state)
                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) {
                SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
+               pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
                return STTD_ERROR_INVALID_PARAMETER;
        }
 
@@ -636,6 +641,8 @@ int sttd_recorder_stop()
 #ifdef BUF_SAVE_MODE
        fclose(g_pFile);
 #endif
+       pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
+       SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Leave critical section");
 
        return 0;
 }