Fix memory leak on tts_streaming thread 66/207566/2
authorwn.jang <wn.jang@samsung.com>
Fri, 7 Jun 2019 08:45:49 +0000 (17:45 +0900)
committerwn.jang <wn.jang@samsung.com>
Thu, 13 Jun 2019 05:47:08 +0000 (14:47 +0900)
Change-Id: Iebcf7035772614796f71c50de8c90ed0202e2092

client/vc.c
client/vc_data.cpp
include/voice_control_internal.h

index 77f19a7d4e505605a7b3d2b8ec693ed70bbdbcb7..47fffee62960f1f8016b46d470300b28faf8b594 100644 (file)
@@ -2898,6 +2898,7 @@ static void __start_tts_streaming_thread(void* data, Ecore_Thread* thread)
                                }
                                if (200 < cnt) {
                                        SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Wrong request, there's no pcm data");
+                                       vc_data_clear_tts_data(&tts_data);
                                        return;
                                }
                                cnt++;
@@ -2905,18 +2906,25 @@ static void __start_tts_streaming_thread(void* data, Ecore_Thread* thread)
                        SLOG(LOG_INFO, TAG_VCC, "[INFO] Finish to wait for new tts data come");
 
                        /* resume tts thread */
+                       vc_data_clear_tts_data(&tts_data);
                        continue;
                }
 
-               SLOG(LOG_DEBUG, TAG_VCC, "tts streaming callback is called");
-               vc_client_use_callback(g_vc);
-               callback(tts_data->event, tts_data->data, tts_data->data_size, tts_data->utt_id, user_data);
-               vc_client_not_use_callback(g_vc);
+               if (NULL != tts_data) {
+                       SLOG(LOG_DEBUG, TAG_VCC, "tts streaming callback is called");
+                       vc_client_use_callback(g_vc);
+                       callback(tts_data->event, tts_data->data, tts_data->data_size, tts_data->utt_id, user_data);
+                       vc_client_not_use_callback(g_vc);
 
-               /* If no tts data and EVENT_FINISH */
-               if (0 >= vc_data_get_tts_data_size() && VC_TTS_EVENT_FINISH == tts_data->event) {
-                       SLOG(LOG_INFO, TAG_VCC, "[INFO] Finish tts");
-                       break;
+                       /* If no tts data and EVENT_FINISH */
+                       if (0 >= vc_data_get_tts_data_size() && VC_TTS_EVENT_FINISH == tts_data->event) {
+                               SLOG(LOG_INFO, TAG_VCC, "[INFO] Finish tts");
+                               free(tts_data);
+                               tts_data = NULL;
+                               break;
+                       }
+                       free(tts_data);
+                       tts_data = NULL;
                }
        }
 }
index 2358f6f45388176861d26e384192dfa355c1f2a3..850d2e1d60acb77d460cc16fb1db466a37c3ef31 100644 (file)
@@ -99,7 +99,7 @@ int vc_data_clear_tts_data(vc_tts_data_s** data)
 
        pthread_mutex_lock(&g_tts_data_mutex);
 
-       if (!g_tts_data.empty()) {
+       if (NULL != *data) {
                SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] event(%d) data(%p) size(%d)", (*data)->event, (*data)->data, (*data)->data_size);
 
                if (NULL != (*data)->data) {
@@ -143,4 +143,4 @@ int vc_data_clear_tts_data_by_uttid(int utt_id)
        pthread_mutex_unlock(&g_tts_data_mutex);
 
        return VC_ERROR_NONE;
-}
\ No newline at end of file
+}
index cfbb9ea4459e0eb76f785a337c2d68befc1f83df..131c7e5505650ed1ef75a676202ab291674fa39e 100644 (file)
@@ -61,6 +61,8 @@ typedef bool (*vc_asr_result_cb)(vc_result_event_e event, const char* result, vo
  * @brief Called when client gets TTS streaming data from vc engine service.
  * @since_tizen 4.0
  *
+ * @remarks The @a buffer must be released with free() by you when you no longer need it.
+ *
  * @param[in] event The TTS event
  * @param[in] buffer The TTS streaming data
  * @param[in] len The length of the TTS streaming data