#include "privacy_view.h"
#define DEFAULT_ICON_PATH _TZ_SYS_RO_APP"/org.tizen.privacy-setting/res/icon/default.png"
+#define SUCCESS 1
+#define FAIL 0
typedef struct pg_data_list_struct {
pg_data_s *pg_data;
static pg_data_list *start;
static pg_data_list *cur;
-void init_pg_data_list(void)
+int init_pg_data_list(void)
{
start = (pg_data_list *)malloc(sizeof(pg_data_list) * 1);
+ if (start == NULL) {
+ LOGE("Failed to allocate memory");
+ return FAIL;
+ }
+
start->next = NULL;
cur = start;
+
+ return SUCCESS;
}
-void add_pg_data(const char *package_id, const int count, time_t time, const int monitor_policy)
+int add_pg_data(const char *package_id, const int count, time_t time, const int monitor_policy)
{
pg_data_list *node = (pg_data_list *)malloc(sizeof(pg_data_list) * 1);
+ if (node == NULL) {
+ LOGE("Failed to allocate memory");
+ return FAIL;
+ }
+
node->pg_data = (pg_data_s *)malloc(sizeof(pg_data_s));
+ if (node->pg_data == NULL) {
+ LOGE("Failed to allocate memory");
+ free(node);
+ return FAIL;
+ }
+
node->next = NULL;
+
node->pg_data->pkg_id = strdup(package_id);
+ if (node->pg_data->pkg_id == NULL) {
+ LOGE("Failed to allocate memory");
+ free(node->pg_data);
+ free(node);
+ return FAIL;
+ }
+
node->pg_data->count = count;
node->pg_data->time = time;
node->pg_data->monitor_policy = monitor_policy;
cur->next = node;
cur = node;
len++;
+
+ return SUCCESS;
}
static void free_pg_data(pg_data_list *node, pg_data_list *next)
free_pg_data(next, next->next);
if (node == start) {
- free(start);
+ if (start != NULL) {
+ free(start);
+ start = NULL;
+ }
return;
} else {
+
if (node != NULL && node->pg_data != NULL && node->pg_data->pkg_id != NULL)
free(node->pg_data->pkg_id);
if (data != NULL) {
if (data->label != NULL) {
free(data->label);
+
if (*is_description == 0) {
*is_description = 1;
return;
if (data->description != NULL)
free(data->description);
}
+
}
-static void _create_privacy_guard_item_list(void)
+static int _create_privacy_guard_item_list(void)
{
- item_list = (pg_item_data_s **)malloc(sizeof(pg_item_data_s *) * len);
int j = 0;
- for (j = 0; j < len; j++)
+ item_list = (pg_item_data_s **)malloc(sizeof(pg_item_data_s *) * len);
+ if (item_list == NULL) {
+ LOGE("Failed to allocate memory");
+ return FAIL;
+ }
+
+ for (j = 0; j < len; j++) {
item_list[j] = (pg_item_data_s *)malloc(sizeof(pg_item_data_s));
+ if (item_list[j] == NULL) {
+ LOGE("Failed to allocate memory");
+ return FAIL;
+ }
+ }
+
+ return SUCCESS;
}
static void _free_privacy_guard_item_list(void)
{
+
int is_description = 0;
int j = 0;
+
for (j = 0; j < len; j++) {
free_item(item_list[j], &is_description);
free(item_list[j]);
}
+
free(item_list);
item_list = NULL;
}
+
static void _gl_del_cb(void *data, Evas_Object *obj)
{
is_last++;
static char* _gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
pg_item_data_s *id = data;
+ char *ret = NULL;
- if (!strcmp(part, "elm.text"))
- return strdup(id->label);
+ if (!strcmp(part, "elm.text")) {
+ ret = strdup(id->label);
+ if (ret == NULL) {
+ LOGE("Failed to allocate memory");
+ return NULL;
+ }
+
+ return ret;
+ }
if (!strcmp(part, "elm.text.sub") && id->index != 0) {
if (id->description == NULL)
return NULL;
- return strdup(id->description);
+
+ ret = strdup(id->description);
+ if (ret == NULL) {
+ LOGE("Failed to allocate memory");
+ return NULL;
+ }
+
+ return ret;
}
return NULL;
static bool _privacy_package_info_cb(const char *package_id, const int count, time_t time, const int monitor_policy, void *user_data)
{
- add_pg_data(package_id, count, time, monitor_policy);
+ if (add_pg_data(package_id, count, time, monitor_policy) == FAIL) {
+ LOGE("add_pg_data() is failed.");
+ return false;
+ }
+
return true;
}
{
Evas_Object *genlist = NULL;
is_last = 0;
- init_pg_data_list();
len = 1;
+ if (init_pg_data_list() == FAIL) {
+ LOGE("init_pg_data_list() is failed.");
+ return;
+ }
+
/* Get privacy guard data (pkg, count, policy) list by a privacy */
// user ID
uid_t user_id = getuid();
Elm_Object_Item *it = NULL;
pg_data_list *l = NULL;
- _create_privacy_guard_item_list();
+
+ if (_create_privacy_guard_item_list() == FAIL) {
+ LOGE("_create_privacy_guard_item_list() is failed.");
+ return;
+ }
/* Append guide text to the top of genlist */
pg_item_data_s *description_item = item_list[0];
description_item->index = 0;
snprintf(str_label, sizeof(str_label), "<wrap=word><ellipsis=-1.0><font_size=35><color=#A9A9A9FF>%s</color></font_size></ellipsis></wrap>", dgettext("privacy-setting", "IDS_ST_BODY_THE_SELECTED_APPS_WILL_BE_MONITORED_FOR_ANY_ATTEMPTS_TO_VIOLATE_YOUR_PRIVACY"));
description_item->label = strdup(str_label);
+ if (description_item->label == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
it = elm_genlist_item_append(genlist, itc, description_item, NULL, ELM_GENLIST_ITEM_NONE, _privacy_package_selected_cb, description_item);
elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
// package ID
item->pkg_id = strdup(data->pkg_id);
-
+ if (item->pkg_id == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
+
// package label
res = pkgmgrinfo_pkginfo_get_pkginfo(item->pkg_id, &handle);
if (res != PMINFO_R_OK) {
// title.. (package label)
snprintf(str_temp, sizeof(str_temp), "%s", label);
item->label = strdup(str_temp);
-
+ if (item->label == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
+
// description - e.g.) 25/08/2010 01:30 PM 21 time(s)
if (data->time > 0) {
localtime_r(&data->time, &timeinfo);
snprintf(str_temp, sizeof(str_temp), str_count, data->count);
snprintf(str_label, sizeof(str_label), "<font_size=27>%s <font color=#3DB9CCFF>%s</font></font_size>", str_time, str_temp);
item->description = strdup(str_label);
+ if (item->description == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
} else {
item->description = NULL;
}
// privacy ID
item->privacy_id = strdup(ad->privacy);
-
+ if (item->privacy_id == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
// icon
res = pkgmgrinfo_pkginfo_get_icon(handle, &icon);
if (res != PMINFO_R_OK) {
LOGE("Failed to operate pkgmgrinfo_pkginfo_get_icon [%d]", res);
LOGE("So replace the icon to the default icon");
item->icon = strdup(DEFAULT_ICON_PATH);
+ if (item->icon == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
} else {
if (EINA_TRUE == ecore_file_exists(icon)) {
item->icon = strdup(icon);
+ if (item->icon == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
} else {
LOGD("The icon is not exist for %s. So replace it to the default icon.", label);
item->icon = strdup(DEFAULT_ICON_PATH);
+ if (item->icon == NULL) {
+ LOGE("Failed to allocate memory");
+ return;
+ }
}
}