From f22b9d524188ff3f5aac58f88ecafda276e69ad2 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 21 Aug 2015 19:34:32 +0900 Subject: [PATCH] Fix list iteration save next node beforehand to delete node safely Change-Id: I7d5d88f2bb8d2fb8959fc02f3b5f9134e1c39393 Signed-off-by: Sangyoon Jang --- src/pkgmgrinfo_appinfo.c | 5 +++-- src/pkgmgrinfo_pkginfo.c | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) 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, -- 2.7.4