Fix list iteration 39/46539/4 accepted/tizen/mobile/20150824.134456 accepted/tizen/tv/20150824.134524 accepted/tizen/wearable/20150824.134533 submit/tizen/20150824.024939
authorSangyoon Jang <s89.jang@samsung.com>
Fri, 21 Aug 2015 10:34:32 +0000 (19:34 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 24 Aug 2015 02:03:28 +0000 (19:03 -0700)
save next node beforehand to delete node safely

Change-Id: I7d5d88f2bb8d2fb8959fc02f3b5f9134e1c39393
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_pkginfo.c

index e59c3c8..f37fea7 100644 (file)
@@ -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,
index be7df99..8254e5c 100644 (file)
@@ -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,