From a3d31b58d2b743ac2f34ffc5d2f4ee1c4326b318 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 20 Jan 2013 18:45:03 -0800 Subject: [PATCH] shared: Mark and skip notification callbacks when become invalid --- src/shared/mgmt.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index 835255020..d45c1c4af 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -77,6 +77,7 @@ struct mgmt_notify { unsigned int id; uint16_t event; uint16_t index; + bool destroyed; mgmt_notify_func_t callback; mgmt_destroy_func_t destroy; void *user_data; @@ -235,6 +236,9 @@ static void process_notify(struct mgmt *mgmt, uint16_t event, uint16_t index, list = g_list_next(list)) { struct mgmt_notify *notify = list->data; + if (notify->destroyed) + continue; + if (notify->event != event) continue; @@ -709,6 +713,8 @@ bool mgmt_unregister(struct mgmt *mgmt, unsigned int id) return true; } + notify->destroyed = true; + mgmt->notify_destroyed = g_list_concat(mgmt->notify_destroyed, list); return true; @@ -737,6 +743,8 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index) continue; } + notify->destroyed = true; + mgmt->notify_destroyed = g_list_concat(mgmt->notify_destroyed, list); } @@ -744,6 +752,13 @@ bool mgmt_unregister_index(struct mgmt *mgmt, uint16_t index) return true; } +static void mark_notify(gpointer data, gpointer user_data) +{ + struct mgmt_notify *notify = data; + + notify->destroyed = true; +} + bool mgmt_unregister_all(struct mgmt *mgmt) { if (!mgmt) @@ -752,9 +767,11 @@ bool mgmt_unregister_all(struct mgmt *mgmt) if (!mgmt->in_notify) { g_list_foreach(mgmt->notify_list, destroy_notify, NULL); g_list_free(mgmt->notify_list); - } else + } else { + g_list_foreach(mgmt->notify_list, mark_notify, NULL); mgmt->notify_destroyed = g_list_concat(mgmt->notify_destroyed, mgmt->notify_list); + } mgmt->notify_list = NULL; -- 2.47.3