memory leak fix - missed to free user data from g_object_get 41/49441/4 accepted/tizen/tv/20151014.043253 submit/tizen/20151014.005748
authorSoohye Shin <soohye.shin@samsung.com>
Tue, 13 Oct 2015 08:33:42 +0000 (17:33 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Tue, 13 Oct 2015 11:54:58 +0000 (20:54 +0900)
Change-Id: I1c485157ba91f9c4163035869eefaa572b17bbf2
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
src/data/data_home.c

index 4c22cb3..54c926f 100644 (file)
@@ -75,34 +75,86 @@ static inline gboolean _read_boolean(JsonReader *reader, char *member)
        return val;
 }
 
-static void _get_login_user(char **name, char **icon, char **focus_icon)
+static bool _get_login_user(struct datamgr_item *di)
 {
        GumUser *user;
        uid_t uid = getuid();
+       char *name, *icon, *focus_icon;
 
        user = gum_user_get_sync(uid, FALSE);
        if (!user) {
                _ERR("failed to get user service");
-               return;
+               return false;
        }
 
-       g_object_get(G_OBJECT(user), GUM_ATTR_NAME, name, GUM_ATTR_ICON, icon,
+       g_object_get(G_OBJECT(user), GUM_ATTR_NAME, &name, GUM_ATTR_ICON, &icon,
                        NULL);
+       if (!name || !icon) {
+               _ERR("failed to get user info");
+               free(name);
+               free(icon);
+               return false;
+       }
 
-       if (!*icon || strlen(*icon) == 0)
-               *icon = IMAGE_USER_DEFAULT;
-
-       *focus_icon = (char *)utils_get_focus_icon_from_icon(*icon);
+       di->title = name;
+       if (strlen(icon) == 0) {
+               free(icon);
+               di->icon = strdup(IMAGE_USER_DEFAULT);
+               di->focus_icon = strdup(IMAGE_USER_DEFAULT_FOCUS);
+       } else {
+               di->icon = icon;
+               focus_icon = (char *)utils_get_focus_icon_from_icon(icon);
+               di->focus_icon = strdup(focus_icon);
+       }
 
        g_object_unref(user);
+
+       return true;
 }
 
-static struct datamgr_item *_pack_home_item(JsonReader *reader, int i)
+static struct datamgr_item *_new_datamgr_item(char *name, char *icon,
+               char *focus_icon, char *parameter, char *action, bool noti)
 {
        struct datamgr_item *di;
+       char buf[MAX_BUF];
+
+       di = calloc(1, sizeof(*di));
+       if (!di) {
+               _ERR("failed to calloc home item");
+               return NULL;
+       }
+
+       di->parameter = strdup(parameter);
+       di->noti = noti;
+       if (noti) {
+               snprintf(buf, sizeof(buf), "%d",
+                               utils_get_notification_count());
+               di->subtitle = strdup(buf);
+       }
+
+       if (!strcmp(action, STR_SELECT_ACTION_PUSH) && _get_login_user(di)) {
+               di->action = ITEM_SELECT_ACTION_PUSH;
+               return di;
+       } else if (!strcmp(action, STR_SELECT_ACTION_LAUNCH)) {
+               di->action = ITEM_SELECT_ACTION_LAUNCH;
+       } else {
+               free(di->parameter);
+               free(di->subtitle);
+               free(di);
+               return NULL;
+       }
+
+       di->title = strdup(name);
+       di->icon = strdup(icon);
+       di->focus_icon = strdup(focus_icon);
+
+       return di;
+}
+
+static struct datamgr_item *_pack_home_item(JsonReader *reader, int i)
+{
        char *name, *icon, *parameter, *focus_icon, *action;
        gboolean noti;
-       char buf[MAX_BUF];
 
        if (!reader) {
                _ERR("Invalid argument");
@@ -132,32 +184,8 @@ static struct datamgr_item *_pack_home_item(JsonReader *reader, int i)
 
        json_reader_end_element(reader);
 
-       di = calloc(1, sizeof(*di));
-       if (!di) {
-               _ERR("failed to calloc home item");
-               return NULL;
-       }
-
-       if (!strcmp(action, STR_SELECT_ACTION_PUSH)) {
-               di->action = ITEM_SELECT_ACTION_PUSH;
-               _get_login_user(&name, &icon, &focus_icon);
-       } else if (!strcmp(action, STR_SELECT_ACTION_LAUNCH))
-               di->action = ITEM_SELECT_ACTION_LAUNCH;
-       else
-               di->action = ITEM_SELECT_ACTION_MAX;
-
-       di->title = strdup(name);
-       di->icon = strdup(icon);
-       di->focus_icon = strdup(focus_icon);
-       di->parameter = strdup(parameter);
-       di->noti = noti;
-       if (noti) {
-               snprintf(buf, sizeof(buf), "%d",
-                               utils_get_notification_count());
-               di->subtitle = strdup(buf);
-       }
-
-       return di;
+       return _new_datamgr_item(name, icon, focus_icon, parameter, action,
+                       noti);
 err:
        json_reader_end_element(reader);
        return NULL;