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>
}
}
+ g_list_free(client_list);
+
return;
}
iter = g_list_next(iter);
}
}
+
+ g_list_free(client_list);
} else {
tts_client_s* client = tts_client_get_by_uid(uid);
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