Fix memory leak of ecore timer
[platform/core/uifw/tts.git] / server / ttsd_server.c
index 5a657a5..afdff96 100755 (executable)
@@ -25,6 +25,9 @@
 #include "ttsd_server.h"
 
 
+#define CLIENT_CLEAN_UP_TIME 500
+
+
 typedef enum {
        TTSD_SYNTHESIS_CONTROL_DOING    = 0,
        TTSD_SYNTHESIS_CONTROL_DONE     = 1,
@@ -42,6 +45,7 @@ typedef struct {
 /* If engine is running */
 static ttsd_synthesis_control_e        g_synth_control;
 
+static Ecore_Timer* g_check_client_timer = NULL;
 static Ecore_Timer* g_wait_timer = NULL;
 
 static utterance_t g_utt;
@@ -198,7 +202,6 @@ int ttsd_send_error(ttse_error_e error, const char* msg)
 }
 
 int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data)
-
 {
        SLOG(LOG_DEBUG, tts_tag(), "===== SEND SYNTHESIS RESULT START");
 
@@ -466,6 +469,11 @@ int ttsd_initialize(ttse_request_callback_s *callback)
                ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
        }
 
+       g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
+       if (NULL == g_check_client_timer) {
+               SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
+       }
+
        return TTSD_ERROR_NONE;
 }
 
@@ -487,6 +495,13 @@ int ttsd_finalize()
 
        ttsd_engine_agent_release();
 
+       if (NULL != g_check_client_timer) {
+               ecore_timer_del(g_check_client_timer);
+               g_check_client_timer = NULL;
+
+               SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore timer handle");
+       }
+
        return TTSD_ERROR_NONE;
 }
 
@@ -521,12 +536,10 @@ int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
 static Eina_Bool __quit_ecore_loop(void *data)
 {
        ttsd_dbus_close_connection();
-
        ttsd_network_finalize();
-
        ttsd_finalize();
-
        ecore_main_loop_quit();
+
        return EINA_FALSE;
 }