Fix double pthread mutex unlock
[platform/core/uifw/tts.git] / client / tts_client.c
index 56c5972..0d9b493 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -77,6 +77,16 @@ int tts_client_new(tts_h* tts)
 
        client->cb_ref_count = 0;
 
+       client->utt_id = 0;
+       client->reason = 0;
+       client->err_msg = NULL;
+
+       client->conn_timer = NULL;
+
+       client->credential = NULL;
+       client->credential_needed = false;
+       client->internal = false;
+
        g_client_list = g_list_append(g_client_list, client);
 
        *tts = temp;
@@ -91,7 +101,7 @@ int tts_client_destroy(tts_h tts)
        if (tts == NULL) {
                SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
                return TTS_ERROR_INVALID_PARAMETER;
-       }       
+       }
 
        GList *iter = NULL;
        tts_client_s *data = NULL;
@@ -106,13 +116,29 @@ int tts_client_destroy(tts_h tts)
                        if (tts->handle == data->tts->handle) {
                                g_client_list = g_list_remove_link(g_client_list, iter);
 
-                               while (0 != data->cb_ref_count)
-                               {
+                               while (0 != data->cb_ref_count) {
                                        /* wait for release callback function */
                                }
+
+                               if (NULL != data->err_msg) {
+                                       free(data->err_msg);
+                                       data->err_msg = NULL;
+                               }
+
+                               if (NULL != data->credential) {
+                                       free(data->credential);
+                                       data->credential = NULL;
+                               }
+
                                free(data);
                                free(tts);
 
+                               data = NULL;
+                               tts = NULL;
+
+                               SLOG(LOG_DEBUG, TAG_TTSC, "Client destroy");
+                               g_list_free(iter);
+
                                return TTS_ERROR_NONE;
                        }