summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunjin Lee <yunjin-.lee@samsung.com>2017-08-07 16:39:38 +0900
committerYunjin Lee <yunjin-.lee@samsung.com>2017-08-07 17:25:59 +0900
commitc867554100b37343291b8a44f4c44e8f00b52985 (patch)
tree833341aa6af0221037b6f42e3b782168cda1be20
parent3c8d6ac756a194186def4fa293a5e36c121d5a3f (diff)
downloadprivacy-setting-c867554100b37343291b8a44f4c44e8f00b52985.tar.gz
privacy-setting-c867554100b37343291b8a44f4c44e8f00b52985.tar.bz2
privacy-setting-c867554100b37343291b8a44f4c44e8f00b52985.zip
Fix memory leak
Change-Id: I371b4d5f5ad1d7fb42619f9a9b6d8de06f5971b1 Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
-rw-r--r--ui/src/privacy_list_view.c25
-rw-r--r--ui/src/privacy_menu_view.c25
-rw-r--r--ui/src/privacy_package_list_view.c90
3 files changed, 76 insertions, 64 deletions
diff --git a/ui/src/privacy_list_view.c b/ui/src/privacy_list_view.c
index 3553aeb..caafff0 100644
--- a/ui/src/privacy_list_view.c
+++ b/ui/src/privacy_list_view.c
@@ -29,24 +29,25 @@
static char* gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
- item_data_s *id = data;
- lreturn_if(!strcmp(part, "elm.text"), , strdup(id->title), "privacy = %s", id->title);
+ char* privacy_display = NULL;
+ char* privacy_name = data;
+ int ret = privilege_info_get_privacy_display(privacy_name, &privacy_display);
+ lreturn_if(!strcmp(part, "elm.text"), , privacy_display, "privacy = %s", data);
return "FAIL";
}
static void gl_del_cb(void *data, Evas_Object *obj)
{
/* Unrealized callback can be called after this. */
/* Accessing item_data_s can be dangerous on unrealized callback. */
- item_data_s *id = data;
- free(id);
+ free(data);
}
static void privacy_selected_cb(void *data, Evas_Object *obj, void *event_info)
{
/* Get selected privacy */
Elm_Object_Item *ei = event_info;
- item_data_s *selected_id = elm_object_item_data_get(ei);
- LOGD("%s is selected, index = %d", selected_id->title, selected_id->index);
+ item_data_s *selected_text = elm_object_item_data_get(ei);
+ LOGD("%s is selected", selected_text);
/* Unhighlight selected item */
elm_genlist_item_selected_set(ei, EINA_FALSE);
@@ -54,7 +55,7 @@ static void privacy_selected_cb(void *data, Evas_Object *obj, void *event_info)
struct app_data_s *ad = (struct app_data_s *)data;
return_if(ad == NULL, , , "ad is null");
- ad->privacy = (char*)selected_id->privacy;
+ ad->privacy = (char*)selected_text;
create_privacy_package_list_view(ad);
}
@@ -74,15 +75,7 @@ void create_privacy_list_view(struct app_data_s *ad)
Elm_Object_Item *it = NULL;
int i = 0;
for (i = 0; i < (int)g_list_length(ad->privacy_list); ++i) {
- item_data_s *id = calloc(sizeof(item_data_s), 1);
- id->index = i;
- char* privacy_display = NULL;
- id->privacy = strdup((char*)g_list_nth_data(ad->privacy_list, i));
- LOGD("privacy = %s", id->privacy);
- int ret = privilege_info_get_privacy_display(id->privacy, &privacy_display);
- log_if(ret != PRVMGR_ERR_NONE, 1, "privacy_display = %s", privacy_display);
- id->title = strdup(privacy_display);
- it = elm_genlist_item_append(genlist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, privacy_selected_cb, ad);
+ it = elm_genlist_item_append(genlist, itc, (char*)g_list_nth_data(ad->privacy_list, i), NULL, ELM_GENLIST_ITEM_NONE, privacy_selected_cb, ad);
log_if(it == NULL, 1, "Error in elm_genlist_item_append");
}
elm_genlist_item_class_free(itc);
diff --git a/ui/src/privacy_menu_view.c b/ui/src/privacy_menu_view.c
index 6c0df8b..d6b6b5a 100644
--- a/ui/src/privacy_menu_view.c
+++ b/ui/src/privacy_menu_view.c
@@ -41,8 +41,8 @@ static Eina_Bool quit_cb(void *data, Elm_Object_Item *it)
static char* gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
- item_data_s *id = data;
- lreturn_if(!strcmp(part, "elm.text"), , strdup(id->title), "selected menu = %s", id->title);
+ char* text = data;
+ lreturn_if(!strcmp(part, "elm.text"), , strdup(text), "selected menu = %s", text);
return "FAIL";
}
@@ -58,16 +58,16 @@ static void gl_del_cb(void *data, Evas_Object *obj)
{
/* Unrealized callback can be called after this. */
/* Accessing item_data_s can be dangerous on unrealized callback. */
- item_data_s *id = data;
- free(id);
+ char* text = data;
+ free(text);
}
static void menu_selected_cb(void *data, Evas_Object *obj, void *event_info)
{
/* Get selected privacy */
Elm_Object_Item *ei = event_info;
- item_data_s *selected_id = elm_object_item_data_get(ei);
- LOGD("%s is selected, index = %d", selected_id->menu, selected_id->index);
+ char *selected_text = elm_object_item_data_get(ei);
+ LOGD("%s is selected", selected_text);
/* Unhighlight selected item */
elm_genlist_item_selected_set(ei, EINA_FALSE);
@@ -78,12 +78,12 @@ static void menu_selected_cb(void *data, Evas_Object *obj, void *event_info)
int ret = privilege_info_get_privacy_list(&(ad->privacy_list));
log_if(ret != PRVMGR_ERR_NONE, 1, "Failed to get privacy_list");
- if (strstr(selected_id->menu, PRIVACY_MENU_SETTING) != NULL) {
+ if (strstr(selected_text, dgettext("privacy-setting", PRIVACY_MENU_SETTING)) != NULL) {
create_privacy_list_view(ad);
- } else if (strstr(selected_id->menu, PRIVACY_MENU_MONITOR) != NULL) {/* privacy guard */
+ } else if (strstr(selected_text, dgettext("privacy-setting", PRIVACY_MENU_MONITOR)) != NULL) {/* privacy guard */
create_privacy_guard_list_view(ad);
} else {
- LOGE("selected_id->title = %s, no matching menu", selected_id->menu);
+ LOGE("selected text = %s, no matching menu", selected_text);
}
}
@@ -116,13 +116,10 @@ void create_privacy_menu_view(struct app_data_s *ad)
elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
int i = 0;
for (i = 0; i < (int)g_list_length(privacy_menu_list); ++i) {
- item_data_s *id = calloc(sizeof(item_data_s), 1);
- id->index = i;
- id->menu = (char*)g_list_nth_data(privacy_menu_list, i);
- id->title = strdup(dgettext("privacy-setting", id->menu));
- it = elm_genlist_item_append(genlist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, menu_selected_cb, ad);
+ it = elm_genlist_item_append(genlist, itc, dgettext("privacy-setting", (char*)g_list_nth_data(privacy_menu_list, i)), NULL, ELM_GENLIST_ITEM_NONE, menu_selected_cb, ad);
log_if(it == NULL, 1, "Error in elm_genlist_item_append");
}
+ elm_genlist_item_class_free(gtc);
elm_genlist_item_class_free(itc);
evas_object_show(genlist);
diff --git a/ui/src/privacy_package_list_view.c b/ui/src/privacy_package_list_view.c
index 795708d..1dc80e2 100644
--- a/ui/src/privacy_package_list_view.c
+++ b/ui/src/privacy_package_list_view.c
@@ -14,8 +14,8 @@
* limitations under the License.
*/
/*
- * @file privacy_package_list_view.c
- * @author Yunjin Lee (yunjin-.lee@samsung.com)
+ * @file privacy_package_list_view.c
+ * @author Yunjin Lee (yunjin-.lee@samsung.com)
* @version 1.0
* @brief
*/
@@ -43,18 +43,45 @@ static bool is_location = false;
static void privacy_package_check_changed_cb(void *data, Evas_Object *obj, void *event_info);
+static void free_pkg_data(pkg_data_s *pkg_data)
+{
+ if(pkg_data->pkgid)
+ free(pkg_data->pkgid);
+ if(pkg_data->label)
+ free(pkg_data->label);
+ if(pkg_data->icon)
+ free(pkg_data->icon);
+ if(pkg_data->applist)
+ g_list_free_full(pkg_data->applist, free);
+ if(pkg_data->privlist)
+ g_list_free_full(pkg_data->privlist, free);
+}
+
+static void free_extension_pkg_data(gpointer pkg_data)
+{
+ free_pkg_data((pkg_data_s*)pkg_data);
+}
+
static void gl_del_cb(void *data, Evas_Object *obj)
{
/* Unrealized callback can be called after this. */
/* Accessing item_data_s can be dangerous on unrealized callback. */
- item_data_s *id = data;
- free(id);
+ if (pkg_data_list != NULL) {
+ g_list_free_full(pkg_data_list, free_extension_pkg_data);
+ pkg_data_list = NULL;
+ }
+}
+
+static void gl_menu_desc_del_cb(void *data, Evas_Object *obj)
+{
+ char *text = data;
+ free(text);
}
static char* gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
- item_data_s *id = data;
- lreturn_if(!strcmp(part, "elm.text"), , strdup(id->title), "privacy-package item = %s", id->title);
+ pkg_data_s *pd = data;
+ lreturn_if(!strcmp(part, "elm.text"), , strdup(pd->label), "privacy-package item = %s", pd->label);
return "FAIL";
}
@@ -74,8 +101,8 @@ static void privacy_package_selected_cb(void *data, Evas_Object *obj, void *even
elm_genlist_item_selected_set(ei, EINA_FALSE);
Eina_Bool status;
- item_data_s *id = (item_data_s*)data;
- if (id->status)
+ pkg_data_s *pd = (pkg_data_s*)data;
+ if (pd->status)
status = EINA_FALSE;
else
status = EINA_TRUE;
@@ -120,7 +147,6 @@ static void __get_package_privacy_status(pkg_data_s* pkg_data, char* privilege_n
break;
} else if (strcmp("Deny", result) == 0 || strcmp("Ask user", result) == 0) {
pkg_data->status = EINA_FALSE;
- break;
} else {
LOGE("Unknown policy level: %s", result);
break;
@@ -164,13 +190,13 @@ static Evas_Object* create_icon(Evas_Object *parent, Evas_Coord w, Evas_Coord h,
static Evas_Object* gl_content_get_cb(void *data, Evas_Object *obj, const char *part)
{
Evas_Object *check;
- item_data_s *id = (item_data_s*)data;
- if (id->icon == NULL)
+ pkg_data_s *pd = (pkg_data_s*)data;
+ if (pd->icon == NULL)
return NULL;
- Eina_Bool status = id->status;
+ Eina_Bool status = pd->status;
if (!strcmp("elm.swallow.icon", part))
- return create_icon(obj, 70, 70, id->icon);
+ return create_icon(obj, 70, 70, pd->icon);
if (strcmp(part, "elm.swallow.end"))
return NULL;
@@ -194,7 +220,7 @@ static void privacy_package_check_changed_cb(void *data, Evas_Object *obj, void
Elm_Object_Item *ei = event_info;
elm_genlist_item_selected_set(ei, EINA_FALSE);
Eina_Bool status;
- item_data_s *id = (item_data_s*)data;
+ pkg_data_s *pd = (pkg_data_s*)data;
/* Send policy change request to security-manager */
GList* l;
@@ -204,15 +230,15 @@ static void privacy_package_check_changed_cb(void *data, Evas_Object *obj, void
for (l = pkg_data_list; l != NULL; l = l->next) {
pkg_data_s* pkg_data = (pkg_data_s*)l->data;
char* pkgid = (char*)pkg_data->pkgid;
- if (!strcmp(id->pkgid, pkgid)) {
+ if (!strcmp(pd->pkgid, pkgid)) {
char* level;
- if (id->status) {
+ if (pd->status) {
level = "Ask user";
- id->status = false;
+ pd->status = false;
} else {
level = "Allow";
- id->status = true;
+ pd->status = true;
}
LOGD("%s will be changed to %s", pkgid, level);
@@ -318,9 +344,11 @@ static int pkg_list_cb(pkgmgrinfo_pkginfo_h filter_handle, void *user_data)
/* Make package data item */
pkg_data_s *pkg_data = (pkg_data_s *)malloc(sizeof(pkg_data_s));
+ return_if(pkg_data == NULL, pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkg_data malloc failed");
/* Add pkg id to package data item */
pkg_data->pkgid = strdup(pkgid);
+ return_if(pkg_data->pkgid == NULL, pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "strdup of pkgid failed");
/* Add privilege info to package data item */
pkg_data->privlist = NULL;
@@ -329,23 +357,23 @@ static int pkg_list_cb(pkgmgrinfo_pkginfo_h filter_handle, void *user_data)
/* Add app list to package data item */
pkg_data->applist = NULL;
ret = pkgmgrinfo_appinfo_get_list(pkg_handle, PMINFO_ALL_APP, pkg_app_list_cb, pkg_data);
- return_if(ret != PMINFO_R_OK, pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_appinfo_get_list failed");
+ return_if(ret != PMINFO_R_OK, free_pkg_data(pkg_data); pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_appinfo_get_list failed");
/* See if the package is global. TBD: If notion for handling of global app is required. */
pkg_data->is_global = false;
ret = pkgmgrinfo_pkginfo_is_global(pkg_handle, &pkg_data->is_global);
- return_if(ret != PMINFO_R_OK, pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_pkginfo_is_global failed");
+ return_if(ret != PMINFO_R_OK, free_pkg_data(pkg_data); pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_pkginfo_is_global failed");
/* Get package label */
char* label = NULL;
ret = pkgmgrinfo_pkginfo_get_label(pkg_handle, &label);
- return_if(ret != PMINFO_R_OK, pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_pkginfo_get_label failed");
+ return_if(ret != PMINFO_R_OK, free_pkg_data(pkg_data); pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_pkginfo_get_label failed");
pkg_data->label = strdup(label);
/* Get package icon path */
char* icon = NULL;
ret = pkgmgrinfo_pkginfo_get_icon(pkg_handle, &icon);
- return_if(ret != PMINFO_R_OK, pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_pkginfo_get_icon failed");
+ return_if(ret != PMINFO_R_OK, free_pkg_data(pkg_data); pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle), -1, "pkgmgrinfo_pkginfo_get_icon failed");
if (EINA_TRUE == ecore_file_exists(icon))
pkg_data->icon = strdup(icon);
else
@@ -366,11 +394,11 @@ static int get_uniq_pkg_list_by_privacy(const char* privacy)
int ret = 0;
/* For privilege list loop -> Get pkg_list by privilege */
if (pkg_list != NULL) {
- g_list_free(pkg_list);
+ g_list_free_full(pkg_list, free);
pkg_list = NULL;
}
if (pkg_data_list != NULL) {
- g_list_free(pkg_data_list);
+ g_list_free_full(pkg_data_list, free_extension_pkg_data);
pkg_data_list = NULL;
}
GList* l;
@@ -421,7 +449,7 @@ void create_privacy_package_list_view(struct app_data_s* ad)
/* Get privilege list by privacy */
if (privilege_list != NULL) {
- g_list_free(privilege_list);
+ g_list_free_full(privilege_list, free);
privilege_list = NULL;
}
int ret = privilege_info_get_privilege_list_by_privacy(ad->privacy, &privilege_list);
@@ -465,24 +493,17 @@ void create_privacy_package_list_view(struct app_data_s* ad)
mtc->item_style = "multiline";
mtc->func.text_get = gl_menu_desc_text_get_cb;
- mtc->func.del = gl_del_cb;
+ mtc->func.del = gl_menu_desc_del_cb;
it = elm_genlist_item_append(genlist, mtc, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
log_if(it == NULL, 1, "Error in elm_genlist_item_append");
elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
for (l = pkg_data_list; l != NULL; l = l->next) {
- item_data_s *id = calloc(sizeof(item_data_s), 1);
- id->index = i++;
pkg_data_s* pkg_data = (pkg_data_s*)l->data;
- id->pkgid = strdup(pkg_data->pkgid);
- id->title = pkg_data->label;
- id->icon = pkg_data->icon;
/* Get privacy status of given package */
- id->status = get_package_privacy_status(pkg_data->pkgid);
- LOGD("status = %d", id->status);
LOGD("before add");
- it = elm_genlist_item_append(genlist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, privacy_package_selected_cb, id);
+ it = elm_genlist_item_append(genlist, itc, pkg_data, NULL, ELM_GENLIST_ITEM_NONE, privacy_package_selected_cb, pkg_data);
LOGD("after add");
log_if(it == NULL, 1, "Error in elm_genlist_item_append");
}
@@ -491,4 +512,5 @@ void create_privacy_package_list_view(struct app_data_s* ad)
}
/* Push naviframe item */
Elm_Object_Item *nf_it = elm_naviframe_item_push(ad->nf, privacy_display, common_back_btn_add(ad), NULL, genlist, NULL);
+
}