From 6f06976cb0b09e3d78ea746a7d64fe377885ce14 Mon Sep 17 00:00:00 2001 From: Nilesh Trimbake Date: Mon, 8 Oct 2018 19:15:22 +0530 Subject: [PATCH] Resolve double memory free issue. This patch resolve possible double memory free. Change-Id: Ibb6edf11d80dd721bb3397b7c5330d79a48a183b --- src/widget/mp-album-list.c | 74 ++++++++++++++++++++++------------------------ src/widget/mp-track-list.c | 32 ++++++++++---------- 2 files changed, 50 insertions(+), 56 deletions(-) diff --git a/src/widget/mp-album-list.c b/src/widget/mp-album-list.c index c0e15a8..f2c8cf7 100644 --- a/src/widget/mp-album-list.c +++ b/src/widget/mp-album-list.c @@ -697,6 +697,7 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, int index = 0; char *name = NULL; char *artist = NULL; + char *default_artist = NULL; char *title = NULL; char *thumbnail = NULL; @@ -720,6 +721,7 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, } if (!artist || !strlen(artist)) { artist = g_strdup(GET_SYS_STR("IDS_COM_BODY_UNKNOWN")); + default_artist = artist; } title = name; } @@ -732,9 +734,9 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, free(name); name = NULL; } - if (artist) { - free(artist); - artist = NULL; + if (default_artist) { + free(default_artist); + default_artist = NULL; } return; } @@ -745,9 +747,9 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, free(name); name = NULL; } - if (artist) { - free(artist); - artist = NULL; + if (default_artist) { + free(default_artist); + default_artist = NULL; } return; } @@ -779,9 +781,9 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, free(name); name = NULL; } - if (artist) { - free(artist); - artist = NULL; + if (default_artist) { + free(default_artist); + default_artist = NULL; } return; } @@ -795,9 +797,9 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, free(name); name = NULL; } - if (artist) { - free(artist); - artist = NULL; + if (default_artist) { + free(default_artist); + default_artist = NULL; } return; } @@ -810,9 +812,9 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, free(name); name = NULL; } - if (artist) { - free(artist); - artist = NULL; + if (default_artist) { + free(default_artist); + default_artist = NULL; } return; } @@ -828,9 +830,9 @@ static void _mp_album_list_recently_added_thumbpath_clicked_cb(void *data, free(name); name = NULL; } - if (artist) { - free(artist); - artist = NULL; + if (default_artist) { + free(default_artist); + default_artist = NULL; } } @@ -888,16 +890,13 @@ Evas_Object *_mp_album_list_recently_added_content_get(void *data, Evas_Object * for (int index = 0; index < count; index++) { mp_media_info_h item = NULL; char *thumb_path = NULL; + char *default_thumb_path = NULL; char part_name[RECENTLY_ADDED_PART_NAME_MAX_SIZE] = {0, }; item = mp_media_info_group_list_nth_item(svc_handle, index); if (!item) { DEBUG_TRACE ("Fail to mp_media_info_group_list_nth_item, index[%d]", index); - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; - } return NULL; } mp_media_info_group_get_thumbnail_path(item, &thumb_path); @@ -908,13 +907,14 @@ Evas_Object *_mp_album_list_recently_added_content_get(void *data, Evas_Object * "shared_images", DEFAULT_THUMBNAIL); free(shared_path); thumb_path = g_strdup(default_thumbnail); + default_thumb_path = thumb_path; } mp_list_item_data_t *item_data = calloc(1, sizeof(mp_list_item_data_t)); if (!item_data) { - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } return NULL; } @@ -947,9 +947,9 @@ Evas_Object *_mp_album_list_recently_added_content_get(void *data, Evas_Object * evas_object_data_set(content, "genlist_obj", list->genlist); elm_object_signal_callback_add(content, "mouse,clicked,1", "*", _mp_album_list_recently_added_thumbpath_clicked_cb, item_data); - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } return content; } @@ -980,15 +980,15 @@ Evas_Object *_mp_album_list_recently_added_content_get(void *data, Evas_Object * evas_object_data_set(content, "genlist_obj", list->genlist); elm_object_signal_callback_add(content, "mouse,clicked,1", "*", _mp_album_list_recently_added_play_icon_clicked_cb, item_data); - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } return content; } - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } } return NULL; @@ -1021,12 +1021,8 @@ static void _mp_album_list_append_recently_added(void *thiz, mp_media_list_h svc MpAlbumList_t *list = thiz; MP_CHECK(list); MP_CHECK(list->recently_added_genlist); - mp_list_item_data_t *item_data; - item_data = mp_list_item_data_create(MP_LIST_ITEM_TYPE_GROUP_TITLE); - MP_CHECK(item_data); - item_data->it = - elm_genlist_item_append(list->recently_added_genlist, list->itc_genlist_recently_added, svc_handle, + elm_genlist_item_append(list->recently_added_genlist, list->itc_genlist_recently_added, svc_handle, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); } diff --git a/src/widget/mp-track-list.c b/src/widget/mp-track-list.c index fc6edd4..84e84b8 100644 --- a/src/widget/mp-track-list.c +++ b/src/widget/mp-track-list.c @@ -972,6 +972,7 @@ Evas_Object *_mp_track_list_recently_added_content_get(void *data, Evas_Object * for (int index = 0; index < count; index++) { mp_media_info_h item = NULL; char *thumb_path = NULL; + char *default_thumb_path = NULL; char part_name[RECENTLY_ADDED_PART_NAME_MAX_SIZE] = {0, }; item = mp_media_info_list_nth_item(svc_handle, index); @@ -988,13 +989,14 @@ Evas_Object *_mp_track_list_recently_added_content_get(void *data, Evas_Object * "shared_images", DEFAULT_THUMBNAIL); free(shared_path); thumb_path = g_strdup(default_thumbnail); + default_thumb_path = thumb_path; } mp_list_item_data_t *item_data = calloc(1, sizeof(mp_list_item_data_t)); if (!item_data) { - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } return NULL; } @@ -1027,9 +1029,9 @@ Evas_Object *_mp_track_list_recently_added_content_get(void *data, Evas_Object * evas_object_data_set(content, "genlist_obj", list->genlist); elm_object_signal_callback_add(content, "mouse,clicked,1", "*", _mp_track_list_recently_added_thumbpath_clicked_cb, NULL); - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } return content; } @@ -1059,15 +1061,15 @@ Evas_Object *_mp_track_list_recently_added_content_get(void *data, Evas_Object * evas_object_data_set(content, "genlist_obj", list->genlist); elm_object_signal_callback_add(content, "mouse,clicked,1", "*", _mp_track_list_recently_added_play_icon_clicked_cb, item_data); - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } return content; } - if (thumb_path) { - free(thumb_path); - thumb_path = NULL; + if (default_thumb_path) { + free(default_thumb_path); + default_thumb_path = NULL; } } return NULL; @@ -1100,12 +1102,8 @@ static void _mp_track_list_append_recently_added(void *thiz, mp_media_list_h svc MpTrackList_t *list = thiz; MP_CHECK(list); MP_CHECK(list->recently_added_genlist); - mp_list_item_data_t *item_data; - item_data = mp_list_item_data_create(MP_LIST_ITEM_TYPE_GROUP_TITLE); - MP_CHECK(item_data); - item_data->it = - elm_genlist_item_append(list->recently_added_genlist, list->itc_genlist_recently_added, svc_handle, + elm_genlist_item_append(list->recently_added_genlist, list->itc_genlist_recently_added, svc_handle, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); } -- 2.7.4