forked from Imagelibrary/lwip
netif: fix removing ext-callback while callback is called
When a registered netif ext-callback unregisters itself when being called (e.g. because some state is reached by this event), the invoke iteration might access uninitialized memory or at least stop the iteration (because next is set to null). Fix his by caching the next pointer during iteration before calling callbacks. Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
This commit is contained in:
@@ -1825,11 +1825,11 @@ netif_remove_ext_callback(netif_ext_callback_t* callback)
|
||||
if (iter == callback) {
|
||||
LWIP_ASSERT("last != NULL", last != NULL);
|
||||
last->next = callback->next;
|
||||
callback->next = NULL;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
callback->next = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1846,8 +1846,10 @@ netif_invoke_ext_callback(struct netif *netif, netif_nsc_reason_t reason, const
|
||||
LWIP_ASSERT("netif must be != NULL", netif != NULL);
|
||||
|
||||
while (callback != NULL) {
|
||||
/* cache next pointer: the callback might unregister itself */
|
||||
netif_ext_callback_t *next = callback->next;
|
||||
callback->callback_fn(netif, reason, args);
|
||||
callback = callback->next;
|
||||
callback = next;
|
||||
}
|
||||
}
|
||||
#endif /* LWIP_NETIF_EXT_STATUS_CALLBACK */
|
||||
|
||||
Reference in New Issue
Block a user