From: Yunmi Ha Date: Tue, 2 Jun 2020 04:57:10 +0000 (+0900) Subject: Add DD_LIST_FOREACH_SAFE function X-Git-Tag: accepted/tizen/6.0/unified/20201030.115623~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F73%2F235073%2F1;p=platform%2Fcore%2Fsystem%2Flibsvi.git Add DD_LIST_FOREACH_SAFE function DD_LIST_FOREACH_SAFE function allows you to safely delete a list item in a foreach statement. Change-Id: Ic6bc0bf11e62161f9ff2769a66439197d6b81b39 Signed-off-by: Yunmi Ha --- diff --git a/src/common.h b/src/common.h index 650e27a..0a206d5 100644 --- a/src/common.h +++ b/src/common.h @@ -52,6 +52,10 @@ typedef GList dd_list; a = g_list_remove(a, b) #define DD_LIST_FOREACH(head, elem, node) \ for (elem = head; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) +#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ + for (elem = head, elem_next=g_list_next(elem), node = NULL; \ + elem && ((node = elem->data) != NULL); \ + elem = elem_next, elem_next = g_list_next(elem), node=NULL) #endif #define FEEDBACK_DATA_DIR FEEDBACK_SYS_SHARE"/feedback" diff --git a/src/dbus.c b/src/dbus.c index ff20c1b..d315962 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -432,7 +432,7 @@ int unregister_signal_handler(feedback_restart_cb func) { GDBusConnection *conn; struct feedback_restart_callback *callback; - dd_list *elem; + dd_list *elem, *next; if (!func) return -EINVAL; @@ -445,7 +445,7 @@ int unregister_signal_handler(feedback_restart_cb func) //LCOV_EXCL_STOP } - DD_LIST_FOREACH(callback_list, elem, callback) { + DD_LIST_FOREACH_SAFE(callback_list, elem, next, callback) { if (callback->func != func) continue; if (callback->feedback_id > 0)