util/addon: make wlr_addon_set_finish() safer

wl_list_for_each_safe() breaks if an item immediately after the current
one is removed, see
https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4358#note_2106260.
This commit is contained in:
Kirill Primak 2023-10-08 13:21:00 +03:00 committed by Simon Ser
parent b06c2f3d1f
commit 2c33a1c2de
1 changed files with 8 additions and 8 deletions

View File

@ -11,16 +11,16 @@ void wlr_addon_set_init(struct wlr_addon_set *set) {
} }
void wlr_addon_set_finish(struct wlr_addon_set *set) { void wlr_addon_set_finish(struct wlr_addon_set *set) {
struct wlr_addon *addon, *tmp; while (!wl_list_empty(&set->addons)) {
wl_list_for_each_safe(addon, tmp, &set->addons, link) { struct wl_list *link = set->addons.next;
struct wlr_addon *addon = wl_container_of(link, addon, link);
const struct wlr_addon_interface *impl = addon->impl;
addon->impl->destroy(addon); addon->impl->destroy(addon);
if (set->addons.next == link) {
wlr_log(WLR_ERROR, "Dangling addon: %s", impl->name);
abort();
}
} }
wl_list_for_each(addon, &set->addons, link) {
wlr_log(WLR_ERROR, "Dangling addon: %s", addon->impl->name);
}
assert(wl_list_empty(&set->addons));
} }
void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set, void wlr_addon_init(struct wlr_addon *addon, struct wlr_addon_set *set,