Fix memory leak
[platform/core/uifw/tts.git] / server / ttsd_data.cpp
index 932ea35..47e335b 100644 (file)
 
 using namespace std;
 
-typedef struct 
+typedef struct
 {
        char*   lang;
        int     vctype;
 }used_voice_s;
 
-typedef struct 
+typedef struct
 {
        int             pid;
        int             uid;
        int             utt_id_stopped;
-       app_state_e     state;
+       app_tts_state_e state;
 
        std::list<speak_data_s*> m_speak_data;
        std::list<sound_data_s*> m_wav_data;
@@ -41,8 +41,13 @@ typedef struct
 
 static vector<app_data_s> g_app_list;
 
+static pthread_mutex_t g_speak_data_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t g_sound_data_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+
+/* If engine is running */
+static ttsd_synthesis_control_e        g_synth_control;
+
 /*
 * functions for debug
 */
@@ -68,13 +73,15 @@ int __data_show_list()
 int __data_show_sound_list(int index)
 {
        SLOG(LOG_DEBUG, tts_tag(), "----- Sound list -----");
-       
+
        unsigned int i = 0;
-       std::list<sound_data_s*>::iterator iter;
-       for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); iter++) {
-               SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%ld), uttid(%d), type(%d)", 
-                       i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
-               i++;
+       if (!g_app_list[index].m_wav_data.empty()) {
+               std::list<sound_data_s*>::iterator iter;
+               for (iter = g_app_list[index].m_wav_data.begin(); (NULL != *iter && iter != g_app_list[index].m_wav_data.end()); ++iter) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%d), uttid(%d), type(%d)",
+                                       i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
+                       i++;
+               }
        }
 
        if (i == 0) {
@@ -90,11 +97,13 @@ int __data_show_text_list(int index)
        SLOG(LOG_DEBUG, tts_tag(), "----- Text list -----");
 
        unsigned int i = 0;
-       std::list<speak_data_s*>::iterator iter;
-       for (iter = g_app_list[index].m_speak_data.begin(); iter != g_app_list[index].m_speak_data.end(); iter++) {
-               SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)", 
-                       i + 1, *iter, (*iter)->lang, (*iter)->vctype, (*iter)->speed, (*iter)->utt_id, (*iter)->text);
-               i++;
+       if (!g_app_list[index].m_speak_data.empty()) {
+               std::list<speak_data_s*>::iterator iter;
+               for (iter = g_app_list[index].m_speak_data.begin(); (NULL != *iter && iter != g_app_list[index].m_speak_data.end()); ++iter) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)", 
+                                       i + 1, *iter, (*iter)->lang, (*iter)->vctype, (*iter)->speed, (*iter)->utt_id, (*iter)->text);
+                       i++;
+               }
        }
 
        if (0 == i) {
@@ -110,10 +119,12 @@ int __data_show_used_voice_list(int index)
        SLOG(LOG_DEBUG, tts_tag(), "----- Used voice list -----");
 
        unsigned int i = 0;
-       std::list<used_voice_s>::iterator iter;
-       for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); iter++) {
-               SLOG(LOG_DEBUG, tts_tag(), "[%dth] lang(%s), vctype(%d)", i + 1, iter->lang, iter->vctype);
-               i++;
+       if (!g_app_list[index].m_used_voice.empty()) {
+               std::list<used_voice_s>::iterator iter;
+               for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); ++iter) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[%dth] lang(%s), vctype(%d)", i + 1, iter->lang, iter->vctype);
+                       i++;
+               }
        }
 
        if (0 == i) {
@@ -128,6 +139,17 @@ int __data_show_used_voice_list(int index)
 * ttsd data functions
 */
 
+int ttsd_set_synth_control(ttsd_synthesis_control_e control)
+{
+       g_synth_control = control;
+       return 0;
+}
+
+ttsd_synthesis_control_e ttsd_get_synth_control()
+{
+       return g_synth_control;
+}
+
 int ttsd_data_new_client(int pid, int uid)
 {
        if( -1 != ttsd_data_is_client(uid) ) {
@@ -145,7 +167,7 @@ int ttsd_data_new_client(int pid, int uid)
 
 #ifdef DATA_DEBUG
        __data_show_list();
-#endif 
+#endif
        return TTSD_ERROR_NONE;
 }
 
@@ -154,7 +176,7 @@ int ttsd_data_delete_client(int uid)
        int index = 0;
 
        index = ttsd_data_is_client(uid);
-       
+
        if (index < 0) {
                SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
                return -1;
@@ -169,7 +191,7 @@ int ttsd_data_delete_client(int uid)
 
 #ifdef DATA_DEBUG
        __data_show_list();
-#endif 
+#endif
        return TTSD_ERROR_NONE;
 }
 
@@ -179,7 +201,7 @@ int ttsd_data_is_client(int uid)
 
        for (int i = 0; i < vsize; i++) {
                if(g_app_list[i].uid == uid) {
-                       return i;               
+                       return i;
                }
        }
 
@@ -196,7 +218,7 @@ int ttsd_data_get_pid(int uid)
        int index;
 
        index = ttsd_data_is_client(uid);
-       
+
        if (index < 0)  {
                SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -209,13 +231,19 @@ int ttsd_data_get_speak_data_size(int uid)
 {
        int index = 0;
        index = ttsd_data_is_client(uid);
-       
+
        if (index < 0) {
                SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
 
+       /* mutex is locked */
+       pthread_mutex_lock(&g_speak_data_mutex);
        int size = g_app_list[index].m_speak_data.size();
+
+       /* mutex is unlocked */
+       pthread_mutex_unlock(&g_speak_data_mutex);
+
        return size;
 }
 
@@ -231,11 +259,12 @@ int ttsd_data_set_used_voice(int uid, const char* lang, int type)
 
        /* Find voice */
        std::list<used_voice_s>::iterator iter;
-
-       for (iter = g_app_list[index].m_used_voice.begin();iter != g_app_list[index].m_used_voice.end();iter++) {
-               if (0 == strcmp(lang, iter->lang) && type == iter->vctype) {
-                       SLOG(LOG_DEBUG, tts_tag(), "[DATA] The voice is already registered (%s)(%d)", lang, type);
-                       return 0;
+       if (!g_app_list[index].m_used_voice.empty()) {
+               for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end();++iter) {
+                       if (0 == strcmp(lang, iter->lang) && type == iter->vctype) {
+                               SLOG(LOG_DEBUG, tts_tag(), "[DATA] The voice is already registered (%s)(%d)", lang, type);
+                               return 0;
+                       }
                }
        }
 
@@ -244,7 +273,13 @@ int ttsd_data_set_used_voice(int uid, const char* lang, int type)
        used_voice.lang = strdup(lang);
        used_voice.vctype = type;
 
-       g_app_list[index].m_used_voice.insert(g_app_list[index].m_used_voice.end(), used_voice);
+       try {
+               iter = g_app_list[index].m_used_voice.insert(g_app_list[index].m_used_voice.end(), used_voice);
+       } catch (const std::bad_alloc&) {
+               SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_used_voice (bad_alloc)");
+               return -1;
+       }
+       SLOG(LOG_ERROR, tts_tag(), "[DATA] lang(%s), vctype(%d)", iter->lang, iter->vctype);
 
 #ifdef DATA_DEBUG
        __data_show_used_voice_list(index);
@@ -268,19 +303,22 @@ int ttsd_data_reset_used_voice(int uid, ttsd_used_voice_cb callback)
        }
 
        /* Find voice */
-       std::list<used_voice_s>::iterator iter;
+       if (!g_app_list[index].m_used_voice.empty()) {
+               std::list<used_voice_s>::iterator iter;
 
-       for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); iter++) {
-               if (NULL != callback) {
-                       callback(iter->lang, iter->vctype);
-               }
+               for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); ++iter) {
+                       if (NULL != callback) {
+                               callback(iter->lang, iter->vctype);
+                       }
 
-               if (NULL != iter->lang) {
-                       free(iter->lang);
+                       if (NULL != iter->lang) {
+                               free(iter->lang);
+                               iter->lang = NULL;
+                       }
                }
-       } 
 
-       g_app_list[index].m_used_voice.clear();
+               g_app_list[index].m_used_voice.clear();
+       }
 
 #ifdef DATA_DEBUG
        __data_show_used_voice_list(index);
@@ -298,18 +336,55 @@ int ttsd_data_add_speak_data(int uid, speak_data_s* data)
                SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
-       
-       g_app_list[index].m_speak_data.insert(g_app_list[index].m_speak_data.end(), data);
+
+       /* mutex is locked */
+       pthread_mutex_lock(&g_speak_data_mutex);
+
+       std::list<speak_data_s*>::iterator iter;
+
+       try {
+               iter = g_app_list[index].m_speak_data.insert(g_app_list[index].m_speak_data.end(), data);
+       } catch (const std::bad_alloc&) {
+               SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_speak_data (bad_alloc)");
+               pthread_mutex_unlock(&g_speak_data_mutex);
+
+               return TTSD_ERROR_OUT_OF_MEMORY;
+       }
+       SLOG(LOG_ERROR, tts_tag(), "[DATA][%p] utt_id(%d), text(%s), lang(%s), vctype(%d), speed(%d)", 
+                       *iter, (*iter)->utt_id, (*iter)->text, (*iter)->lang, (*iter)->vctype, (*iter)->speed);
 
        if (1 == data->utt_id)
                g_app_list[index].utt_id_stopped = 0;
 
 #ifdef DATA_DEBUG
        __data_show_text_list(index);
-#endif 
+#endif
+       pthread_mutex_unlock(&g_speak_data_mutex);
+
        return TTSD_ERROR_NONE;
 }
 
+int __get_speak_data(int index, speak_data_s** data)
+{
+       if (0 == g_app_list[index].m_speak_data.size()) {
+#ifdef DATA_DEBUG
+               SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] There is no speak data");
+#endif
+               return -1;
+       }
+
+       if (!g_app_list[index].m_speak_data.empty()) {
+               std::list<speak_data_s*>::iterator iter = g_app_list[index].m_speak_data.begin();
+               *data = *iter;
+               g_app_list[index].m_speak_data.pop_front();
+       }
+
+#ifdef DATA_DEBUG
+       __data_show_text_list(index);
+#endif
+       return 0;
+}
+
 int ttsd_data_get_speak_data(int uid, speak_data_s** data)
 {
        int index = 0;
@@ -320,20 +395,17 @@ int ttsd_data_get_speak_data(int uid, speak_data_s** data)
                return TTSD_ERROR_INVALID_PARAMETER;
        }
 
-       if (0 == g_app_list[index].m_speak_data.size()) {
-#ifdef DATA_DEBUG
-               SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] There is no speak data"); 
-#endif 
+       /* mutex is locked */
+       pthread_mutex_lock(&g_speak_data_mutex);
+
+       if (0 != __get_speak_data(index, data)) {
+               SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] There is no speak data");
+               pthread_mutex_unlock(&g_speak_data_mutex);
                return -1;
        }
 
-       std::list<speak_data_s*>::iterator iter = g_app_list[index].m_speak_data.begin();
-       *data = *iter;
-       g_app_list[index].m_speak_data.pop_front();
+       pthread_mutex_unlock(&g_speak_data_mutex);
 
-#ifdef DATA_DEBUG
-       __data_show_text_list(index);
-#endif 
        return TTSD_ERROR_NONE;
 }
 
@@ -354,11 +426,21 @@ int ttsd_data_add_sound_data(int uid, sound_data_s* data)
        /* mutex is locked */
        pthread_mutex_lock(&g_sound_data_mutex);
 
-       g_app_list[index].m_wav_data.insert(g_app_list[index].m_wav_data.end(), data);
+       std::list<sound_data_s*>::iterator iter;
+
+       try {
+               iter = g_app_list[index].m_wav_data.insert(g_app_list[index].m_wav_data.end(), data);
+       } catch (const std::bad_alloc&) {
+               SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_sound_data (bad_alloc)");
+               pthread_mutex_unlock(&g_sound_data_mutex);
+
+               return TTSD_ERROR_OUT_OF_MEMORY;
+       }
+       SLOG(LOG_ERROR, tts_tag(), "[DATA][%p] utt_id(%d), data(%p) data size(%d), type(%d)", *iter, (*iter)->utt_id, (*iter)->data, (*iter)->data_size, (*iter)->audio_type);
 
 #ifdef DATA_DEBUG
        __data_show_sound_list(index);
-#endif 
+#endif
 
        /* mutex is unlocked */
        pthread_mutex_unlock(&g_sound_data_mutex);
@@ -366,11 +448,34 @@ int ttsd_data_add_sound_data(int uid, sound_data_s* data)
        return TTSD_ERROR_NONE;
 }
 
+int __get_sound_data(int index, sound_data_s** data)
+{
+       if (0 == g_app_list[index].m_wav_data.size()) {
+#ifdef DATA_DEBUG
+               SLOG(LOG_DEBUG, tts_tag(), "[DATA] There is no wav data");
+#endif
+               return -1;
+       }
+
+       if (!g_app_list[index].m_wav_data.empty()) {
+               std::list<sound_data_s*>::iterator iter = g_app_list[index].m_wav_data.begin();
+               *data = *iter;
+               g_app_list[index].m_wav_data.pop_front();
+       }
+
+#ifdef DATA_DEBUG
+       __data_show_sound_list(index);
+#endif
+       return 0;
+}
+
 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;
@@ -379,23 +484,12 @@ int ttsd_data_get_sound_data(int uid, sound_data_s** data)
        /* mutex is locked */
        pthread_mutex_lock(&g_sound_data_mutex);
 
-       if (0 == g_app_list[index].m_wav_data.size()) {
-#ifdef DATA_DEBUG
+       if (0 != __get_sound_data(index, data)) {
                SLOG(LOG_DEBUG, tts_tag(), "[DATA] There is no wav data");
-#endif
                /* mutex is unlocked */
                pthread_mutex_unlock(&g_sound_data_mutex);
                return -1;
        }
-
-       std::list<sound_data_s*>::iterator iter = g_app_list[index].m_wav_data.begin();
-       *data = *iter;
-       g_app_list[index].m_wav_data.pop_front();
-
-#ifdef DATA_DEBUG
-       __data_show_sound_list(index);
-#endif 
-
        /* mutex is unlocked */
        pthread_mutex_unlock(&g_sound_data_mutex);
 
@@ -423,6 +517,61 @@ int ttsd_data_get_sound_data_size(int uid)
        return data_size;
 }
 
+int ttsd_data_clear_speak_data(int uid, speak_data_s** speak_data)
+{
+       pthread_mutex_lock(&g_speak_data_mutex);
+
+       int index = 0;
+       index = ttsd_data_is_client(uid);
+       if (index >= 0) {
+               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(int uid, sound_data_s** sound_data)
+{
+       pthread_mutex_lock(&g_sound_data_mutex);
+
+       int index = 0;
+       index = ttsd_data_is_client(uid);
+       if (index >= 0) {
+               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;
@@ -438,8 +587,9 @@ int ttsd_data_clear_data(int uid)
        sound_data_s* temp_sound = NULL;
 
        /* free allocated data */
+       pthread_mutex_lock(&g_speak_data_mutex);
        while(1) {
-               if (0 != ttsd_data_get_speak_data(uid, &temp_speak)) {
+               if (0 != __get_speak_data(index, &temp_speak)) {
                        break;
                }
 
@@ -466,8 +616,12 @@ int ttsd_data_clear_data(int uid)
                g_app_list[index].utt_id_stopped = removed_last_uttid;
        }
 
+       g_app_list[index].m_speak_data.clear();
+       pthread_mutex_unlock(&g_speak_data_mutex);
+
+       pthread_mutex_lock(&g_sound_data_mutex);
        while(1) {
-               if (0 != ttsd_data_get_sound_data(uid, &temp_sound)) {
+               if (0 != __get_sound_data(index, &temp_sound)) {
                        break;
                }
 
@@ -485,13 +639,13 @@ int ttsd_data_clear_data(int uid)
                }
        }
 
-       g_app_list[index].m_speak_data.clear();
        g_app_list[index].m_wav_data.clear();
+       pthread_mutex_unlock(&g_sound_data_mutex);
 
        return TTSD_ERROR_NONE;
 }
 
-int ttsd_data_get_client_state(int uid, app_state_e* state)
+int ttsd_data_get_client_state(int uid, app_tts_state_e* state)
 {
        int index = 0;
 
@@ -506,7 +660,7 @@ int ttsd_data_get_client_state(int uid, app_state_e* state)
        return TTSD_ERROR_NONE;
 }
 
-int ttsd_data_set_client_state(int uid, app_state_e state)
+int ttsd_data_set_client_state(int uid, app_tts_state_e state)
 {
        int index = 0;
 
@@ -555,8 +709,8 @@ int ttsd_data_foreach_clients(ttsd_data_get_client_cb callback, void* user_data)
 
 #ifdef DATA_DEBUG
        __data_show_list();
-#endif 
-       
+#endif
+
        /* Copy app info */
        vector<app_data_s> temp_app_list;
        int vsize = g_app_list.size();
@@ -582,7 +736,7 @@ int ttsd_data_foreach_clients(ttsd_data_get_client_cb callback, void* user_data)
        for (i = 0;i < vsize;i++) {
                temp_app_list.erase(temp_app_list.begin());
        }
-       
+
        return 0;
 }
 
@@ -593,7 +747,7 @@ bool ttsd_data_is_uttid_valid(int uid, int uttid)
        index = ttsd_data_is_client(uid);
        if (index < 0)  {
                SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
-               return TTSD_ERROR_INVALID_PARAMETER;
+               return false;
        }
 
        if (uttid < g_app_list[index].utt_id_stopped)
@@ -608,7 +762,7 @@ int ttsd_data_is_current_playing()
 
        for (int i = 0; i < vsize; i++) {
                if(g_app_list[i].state == APP_STATE_PLAYING) {
-                       return g_app_list[i].uid;               
+                       return g_app_list[i].uid;
                }
        }
 
@@ -622,7 +776,7 @@ int ttsd_data_get_same_pid_client_count(int pid)
 
        for (int i = 0;i < vsize;i++) {
                if(g_app_list[i].pid == pid) {
-                       number++;               
+                       number++;
                }
        }
 
@@ -641,7 +795,7 @@ int ttsd_data_save_error_log(int uid, FILE* fp)
                fprintf(fp, "pid - %d", pid);
        }
        /* app state */
-       app_state_e state;
+       app_tts_state_e state;
        ret = ttsd_data_get_client_state(uid, &state);
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get app state");
@@ -662,26 +816,30 @@ int ttsd_data_save_error_log(int uid, FILE* fp)
        fprintf(fp, "----- Sound list -----");
 
        i = 0;
-       std::list<sound_data_s*>::iterator iter;
-       for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); iter++) {
-               SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%ld), uttid(%d), type(%d)",
-                       i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
-               i++;
+       if (!g_app_list[index].m_wav_data.empty()) {
+               std::list<sound_data_s*>::iterator iter;
+               for (iter = g_app_list[index].m_wav_data.begin(); (NULL != *iter && iter != g_app_list[index].m_wav_data.end()); ++iter) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%d), uttid(%d), type(%d)",
+                                       i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
+                       i++;
+               }
        }
 
        fprintf(fp, "----------------------");
-       
+
        /* get speck data */
        fprintf(fp, "----- Text list -----");
 
        i = 0;
-       std::list<speak_data_s*>::iterator iter_speak;
-       for (iter_speak = g_app_list[index].m_speak_data.begin(); iter_speak != g_app_list[index].m_speak_data.end(); iter_speak++) {
-               SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)",
-                       i, *iter_speak, (*iter_speak)->lang, (*iter_speak)->vctype, (*iter_speak)->speed, (*iter_speak)->utt_id, (*iter_speak)->text);
-               i++;
+       if (!g_app_list[index].m_speak_data.empty()) {
+               std::list<speak_data_s*>::iterator iter_speak;
+               for (iter_speak = g_app_list[index].m_speak_data.begin(); (NULL != *iter_speak && iter_speak != g_app_list[index].m_speak_data.end()); ++iter_speak) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)",
+                                       i, *iter_speak, (*iter_speak)->lang, (*iter_speak)->vctype, (*iter_speak)->speed, (*iter_speak)->utt_id, (*iter_speak)->text);
+                       i++;
+               }
        }
        fprintf(fp, "---------------------");
-       
+
        return 0;
 }