mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-26 00:41:42 +03:00
coap_resource.c: Do not hold the next subscriber across a notification
coap_notify_observers() walked the subscribers with LL_FOREACH_SAFE(), which holds on to the next subscription while the current one is notified. The request handler runs with the lock released, and a notification that cannot be sent disconnects the session, which deletes all of that session's subscriptions. When the next subscription was one of those, the walk carried on with freed memory. Mark the subscriptions to visit at the start of the walk and look up the next marked one from the head of the list after each notification, so nothing deleted during a notification is used afterwards. Subscriptions added during the walk are not notified in that pass, as before. Add a unit test.
This commit is contained in:
1 parent
a8f89ced78
commit
da858655d6
3 files changed
+108
-2
No files matched your search
@@ -65,6 +65,8 @@ struct coap_subscription_t {
|
||||
uint8_t dirty; /**< set if the notification temporarily could not be
|
||||
* sent (in that case, the resource's partially
|
||||
* dirty flag is set too) */
|
||||
uint8_t to_visit; /**< set while coap_notify_observers() has still to
|
||||
* visit this subscription */
|
||||
coap_cache_key_t *cache_key; /** cache_key to identify requester */
|
||||
coap_pdu_t *pdu; /**< PDU to use for additional requests */
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user