Return copy of g_client_list 48/231548/3
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 22 Apr 2020 09:08:40 +0000 (18:08 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 9 Jul 2020 09:03:37 +0000 (18:03 +0900)
This patch changes the return value of tts_client_get_client_list() to copy of g_client_list.
This change supports safe use of g_client_list and avoids thread safety issues.

Originally, this function returns g_client_list directly.
This kind of access is dangerous, because it allows unmanaged modification of list.
This may occur thread safety issue or dangerous memory access.
However, if function returns copy of g_client_list, g_client_list avoids dangerous access.
And also, callee still accesses all of clients through this copied list.

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

index 513a63c2a71f5c637a4f5bf3e8afcf874b33bfd1..4ab960f9b982236ca542b727b5bcddee2b50e841 100644 (file)
@@ -167,6 +167,8 @@ void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_typ
                }
        }
 
+       g_list_free(client_list);
+
        return;
 }
 
@@ -2410,6 +2412,8 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
                                iter = g_list_next(iter);
                        }
                }
+
+               g_list_free(client_list);
        } else {
                tts_client_s* client = tts_client_get_by_uid(uid);
 
index f0f0a823ea210134d69cc6cf45a3ce79e45106e0..0ed68a88f75579c12c41dc396ad59b1fc9a4b20d 100644 (file)
@@ -319,9 +319,13 @@ int tts_client_get_mode_client_count(tts_mode_e mode)
        return number;
 }
 
-// FIXME: remove this function
 GList* tts_client_get_client_list()
 {
-       return g_client_list;
+       GList* copy_list = NULL;
+       pthread_mutex_lock(&g_client_list_mutex);
+       copy_list = g_list_copy(g_client_list);
+       pthread_mutex_unlock(&g_client_list_mutex);
+
+       return copy_list;
 }
 //LCOV_EXCL_STOP