From: Sangyoon Jang Date: Fri, 21 Aug 2015 10:34:32 +0000 (+0900) Subject: Fix list iteration X-Git-Tag: accepted/tizen/mobile/20150824.134456^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f22b9d524188ff3f5aac58f88ecafda276e69ad2;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Fix list iteration save next node beforehand to delete node safely Change-Id: I7d5d88f2bb8d2fb8959fc02f3b5f9134e1c39393 Signed-off-by: Sangyoon Jang --- diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index e59c3c8..f37fea7 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -140,6 +140,7 @@ static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, const char *dbpath; char *locale; GList *tmp; + GList *tmp2; locale = _get_system_locale(); if (locale == NULL) @@ -194,7 +195,8 @@ static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, /* remove duplicate element: * since the list is sorted, we can remove duplicates in linear time */ - for (tmp = *list; tmp; tmp = tmp->next) { + for (tmp = *list, tmp2 = g_list_next(tmp); tmp; + tmp = tmp2, tmp2 = g_list_next(tmp)) { if (tmp->prev == NULL || tmp->data == NULL) continue; if (strcmp((const char *)tmp->prev->data, @@ -203,7 +205,6 @@ static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, } return PMINFO_R_OK; - } static int _appinfo_get_label(sqlite3 *db, const char *appid, diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index be7df99..8254e5c 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -236,6 +236,7 @@ static int _pkginfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, const char *dbpath; char *locale; GList *tmp; + GList *tmp2; locale = _get_system_locale(); if (locale == NULL) @@ -290,7 +291,8 @@ static int _pkginfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, /* remove duplicate element: * since the list is sorted, we can remove duplicates in linear time */ - for (tmp = *list; tmp; tmp = tmp->next) { + for (tmp = *list, tmp2 = g_list_next(tmp); tmp; + tmp = tmp2, tmp2 = g_list_next(tmp)) { if (tmp->prev == NULL || tmp->data == NULL) continue; if (strcmp((const char *)tmp->prev->data,