Assign handle after tts_create() success 34/261934/3
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 29 Jul 2021 06:03:00 +0000 (15:03 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 30 Jul 2021 02:52:45 +0000 (11:52 +0900)
Previous code assigns the new handle before all process of tts_create() is finished. So, if
some process failed, client can get garbage point as a output parameter. It might occur wrong
behavior. And also, wrong pointer is passed into tts_config module because output parameter is
directly used.

This patch makes temporary handle for processing tts_create(), and passes this handle after all
process of tts_create() is success. And also by this change, tts config module gets right pointer
of handle.

Change-Id: I78f32da442b28cf996f357f2b9875a9d4c5e8ec7
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c

index 87bb1cb..065f973 100644 (file)
@@ -206,14 +206,16 @@ int tts_create(tts_h* tts)
                is_first_client = true;
        }
 
-       if (0 != tts_client_new(tts)) {
+       tts_h new_tts = NULL;
+       if (0 != tts_client_new(&new_tts)) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create client!!!!!");
                return TTS_ERROR_OUT_OF_MEMORY;
        }
 
-       tts_client_s* client = tts_client_get(*tts);
+       tts_client_s* client = tts_client_get(new_tts);
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client");
+               tts_client_destroy(new_tts);
                return TTS_ERROR_OPERATION_FAILED;
        }
 
@@ -239,22 +241,23 @@ int tts_create(tts_h* tts)
        }
 
        if (0 != tts_ipc_open_connection(uid)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open dbus connection");
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open ipc connection");
+               tts_client_destroy(new_tts);
                return TTS_ERROR_OPERATION_FAILED;
        }
 
        int ret = tts_config_mgr_initialize(uid);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init config manager : %d", ret);
-               tts_client_destroy(*tts);
+               tts_client_destroy(new_tts);
                return __tts_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(uid, __tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, tts);
+       ret = tts_config_mgr_set_callback(uid, __tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, new_tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                tts_config_mgr_finalize(uid);
-               tts_client_destroy(*tts);
+               tts_client_destroy(new_tts);
                return __tts_convert_config_error_code(ret);
        }
 
@@ -263,11 +266,12 @@ int tts_create(tts_h* tts)
                if (0 != tts_core_initialize()) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize core");
                        tts_config_mgr_finalize(uid);
-                       tts_client_destroy(*tts);
+                       tts_client_destroy(new_tts);
                        return TTS_ERROR_OPERATION_FAILED;
                }
        }
 
+       *tts = new_tts;
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
        return TTS_ERROR_NONE;
 }