mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-21 09:39:58 +00:00
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:
parent
7ec4e9be30
commit
39a9c5a3c5
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user