diff options
author | Soohye Shin <soohye.shin@samsung.com> | 2015-10-13 17:33:42 +0900 |
---|---|---|
committer | Soohye Shin <soohye.shin@samsung.com> | 2015-10-13 20:54:58 +0900 |
commit | 74bb632c50f7ff31ae9624e73685dc330a506c30 (patch) | |
tree | 06c40f86db65557424ee3ed34b4da9cf2550d353 | |
parent | 7ee718a4d7a79d3c62d2f84b97c24f8780d3d7e9 (diff) | |
download | air_home-74bb632c50f7ff31ae9624e73685dc330a506c30.tar.gz air_home-74bb632c50f7ff31ae9624e73685dc330a506c30.tar.bz2 air_home-74bb632c50f7ff31ae9624e73685dc330a506c30.zip |
memory leak fix - missed to free user data from g_object_getsubmit/tizen/20151014.005748accepted/tizen/tv/20151014.043253
Change-Id: I1c485157ba91f9c4163035869eefaa572b17bbf2
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
-rw-r--r-- | src/data/data_home.c | 98 |
1 files changed, 63 insertions, 35 deletions
diff --git a/src/data/data_home.c b/src/data/data_home.c index 4c22cb3..54c926f 100644 --- a/src/data/data_home.c +++ b/src/data/data_home.c @@ -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; |