Fix to deallocate memory of sound and speak data 54/167954/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Thu, 11 Jan 2018 08:47:31 +0000 (17:47 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 23 Jan 2018 05:38:01 +0000 (05:38 +0000)
Change-Id: I071d8f888483b7cf45aa55981b315b1171c1b9ac
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 796e53e9816bbea70c059f38ae04ff698fabb5f9)

server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_player.c
server/ttsd_server.c

index 5626e21..6fc1183 100644 (file)
@@ -428,6 +428,8 @@ int ttsd_data_get_sound_data(int uid, sound_data_s** data)
        int index = 0;
        index = ttsd_data_is_client(uid);
 
+       SLOG(LOG_DEBUG, tts_tag(), "[DATA] sound_data_s: %p", *data);
+
        if (index < 0)  {
                SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -482,6 +484,54 @@ int ttsd_data_get_sound_data_size(int uid)
        return data_size;
 }
 
+int ttsd_data_clear_speak_data(speak_data_s** speak_data)
+{
+       pthread_mutex_lock(&g_speak_data_mutex);
+
+       if (NULL != *speak_data) {
+               SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] utt(%d), text(%s), lang(%s), vctype(%d) speed(%d)", 
+                               (*speak_data)->utt_id, (*speak_data)->text, (*speak_data)->lang, (*speak_data)->vctype, (*speak_data)->speed);
+
+               if (NULL != (*speak_data)->text) {
+                       free((*speak_data)->text);
+                       (*speak_data)->text = NULL;
+               }
+               if (NULL != (*speak_data)->lang) {
+                       free((*speak_data)->lang);
+                       (*speak_data)->lang = NULL;
+               }
+
+               free(*speak_data);
+               *speak_data = NULL;
+       }
+
+       pthread_mutex_unlock(&g_speak_data_mutex);
+
+       return TTSD_ERROR_NONE;
+}
+
+int ttsd_data_clear_sound_data(sound_data_s** sound_data)
+{
+       pthread_mutex_lock(&g_sound_data_mutex);
+
+       if (NULL != *sound_data) {
+               SLOG(LOG_ERROR, tts_tag(), "[DEBUG][%p] event(%d) data(%p) size(%d) rate(%d) utt(%d)", 
+                       (*sound_data), (*sound_data)->event, (*sound_data)->data, (*sound_data)->data_size, (*sound_data)->rate, (*sound_data)->utt_id);
+
+               if (NULL != (*sound_data)->data) {
+                       free((*sound_data)->data);
+                       (*sound_data)->data = NULL;
+               }
+
+               free(*sound_data);
+               *sound_data = NULL;
+       }
+
+       pthread_mutex_unlock(&g_sound_data_mutex);
+
+       return TTSD_ERROR_NONE;
+}
+
 int ttsd_data_clear_data(int uid)
 {
        int index = 0;
index afbd213..23478a9 100644 (file)
@@ -67,6 +67,8 @@ int ttsd_data_get_speak_data(int uid, speak_data_s** data);
 
 int ttsd_data_get_speak_data_size(int uid);
 
+int ttsd_data_clear_speak_data(speak_data_s** speak_data);
+
 /* sound data */
 int ttsd_data_add_sound_data(int uid, sound_data_s* data);
 
@@ -74,6 +76,8 @@ int ttsd_data_get_sound_data(int uid, sound_data_s** data);
 
 int ttsd_data_get_sound_data_size(int uid);
 
+int ttsd_data_clear_sound_data(sound_data_s** sound_data);
+
 int ttsd_data_clear_data(int uid);
 
 
index 54d1ef6..4999021 100644 (file)
@@ -476,12 +476,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        /* unset volume policy, volume will be 100% */
                                        __unset_policy_for_playing();
 
-                                       if (NULL != sound_data->data) {
-                                               free(sound_data->data);
-                                               sound_data->data = NULL;
-                                       }
-                                       free(sound_data);
-                                       sound_data = NULL;
+                                       ttsd_data_clear_sound_data(&sound_data);
                                        return;
                                }
 
@@ -506,12 +501,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                                SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
                                                /* unset volume policy, volume will be 100% */
                                                __unset_policy_for_playing();
-                                               if (NULL != sound_data->data) {
-                                                       free(sound_data->data);
-                                                       sound_data->data = NULL;
-                                               }
-                                               free(sound_data);
-                                               sound_data = NULL;
+                                               ttsd_data_clear_sound_data(&sound_data);
                                                return;
                                        }
                                        if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
@@ -520,12 +510,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        }
                                }
                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
-                               if (NULL != sound_data->data) {
-                                       free(sound_data->data);
-                                       sound_data->data = NULL;
-                               }
-                               free(sound_data);
-                               sound_data = NULL;
+                               ttsd_data_clear_sound_data(&sound_data);
                                continue;
                        }
                }
@@ -541,12 +526,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
 
-                               if (NULL != sound_data->data) {
-                                       free(sound_data->data);
-                                       sound_data->data = NULL;
-                               }
-                               free(sound_data);
-                               sound_data = NULL;
+                               ttsd_data_clear_sound_data(&sound_data);
 
                                return;
                        }
@@ -573,13 +553,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        /* unset volume policy, volume will be 100% */
                                        __unset_policy_for_playing();
 
-                                       if (NULL != sound_data->data) {
-                                               free(sound_data->data);
-                                               sound_data->data = NULL;
-                                       }
-
-                                       free(sound_data);
-                                       sound_data = NULL;
+                                       ttsd_data_clear_sound_data(&sound_data);
 
                                        return;
                                }
@@ -605,15 +579,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
 
-                               if (NULL != sound_data) {
-                                       if (NULL != sound_data->data) {
-                                               free(sound_data->data);
-                                               sound_data->data = NULL;
-                                       }
-
-                                       free(sound_data);
-                                       sound_data = NULL;
-                               }
+                               ttsd_data_clear_sound_data(&sound_data);
 
                                return;
                        }
@@ -654,15 +620,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
                        }
 
-                       if (NULL != sound_data) {
-                               if (NULL != sound_data->data) {
-                                       free(sound_data->data);
-                                       sound_data->data = NULL;
-                               }
-
-                               free(sound_data);
-                               sound_data = NULL;
-                       }
+                       ttsd_data_clear_sound_data(&sound_data);
                        /* unset volume policy, volume will be 100% */
                        __unset_policy_for_playing();
                        return;
@@ -677,13 +635,8 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
-                               if (NULL != sound_data->data) {
-                                       free(sound_data->data);
-                                       sound_data->data = NULL;
-                               }
 
-                               free(sound_data);
-                               sound_data = NULL;
+                               ttsd_data_clear_sound_data(&sound_data);
                                return;
                        }
 
@@ -692,28 +645,15 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        pid, player->uid, sound_data->utt_id);
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
-                               if (NULL != sound_data->data) {
-                                       free(sound_data->data);
-                                       sound_data->data = NULL;
-                               }
 
-                               free(sound_data);
-                               sound_data = NULL;
+                               ttsd_data_clear_sound_data(&sound_data);
                                return;
                        }
 
                        SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
                }
 
-               if (NULL != sound_data) {
-                       if (NULL != sound_data->data) {
-                               free(sound_data->data);
-                               sound_data->data = NULL;
-                       }
-
-                       free(sound_data);
-                       sound_data = NULL;
-               }
+               ttsd_data_clear_sound_data(&sound_data);
 
                if (NULL == g_playing_info) {
                        SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
index 0c99c3a..0731597 100644 (file)
@@ -113,16 +113,7 @@ static int __synthesis(int uid, const char* credential)
 
                        ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
 
-                       if (NULL != speak_data) {
-                               if (NULL != speak_data->lang)   free(speak_data->lang);
-                               if (NULL != speak_data->text)   free(speak_data->text);
-
-                               speak_data->lang = NULL;
-                               speak_data->text = NULL;
-
-                               free(speak_data);
-                               speak_data = NULL;
-                       }
+                       ttsd_data_clear_speak_data(&speak_data);
 
                        return 0;
                }
@@ -153,16 +144,9 @@ static int __synthesis(int uid, const char* credential)
                        g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
                }
 
-               if (NULL != speak_data) {
-                       if (NULL != speak_data->lang)   free(speak_data->lang);
-                       if (NULL != speak_data->text)   free(speak_data->text);
-
-                       speak_data->lang = NULL;
-                       speak_data->text = NULL;
-
-                       free(speak_data);
-                       speak_data = NULL;
-               }
+               ttsd_data_clear_speak_data(&speak_data);
+       } else {
+               ttsd_data_clear_speak_data(&speak_data);
        }
 
        SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS  END");