mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-01 02:27:09 +03:00
Observe: Fix coap_free_context() assert when active observe
src/net.c: Call coap_delete_all_resources() (which may send a CON observe bumping a session ref count) before coap_delete_all() to remove any CON transmissions that are still in flight in cop_free_context(). src/resource.c: Delete observer if GET handler does not return a 2.xx code.
This commit is contained in:
1 parent
f29f053d53
commit
9de0ff377a
2 files changed
+6
-5
No files matched your search
@@ -586,6 +586,9 @@ coap_free_context(coap_context_t *context) {
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
/* Removing a resource may cause a CON observe to be sent */
|
||||
coap_delete_all_resources(context);
|
||||
|
||||
coap_delete_all(context->sendqueue);
|
||||
|
||||
#ifdef WITH_LWIP
|
||||
@@ -593,8 +596,6 @@ coap_free_context(coap_context_t *context) {
|
||||
coap_retransmittimer_restart(context);
|
||||
#endif
|
||||
|
||||
coap_delete_all_resources(context);
|
||||
|
||||
#ifndef WITHOUT_ASYNC
|
||||
coap_delete_all_async(context);
|
||||
#endif /* WITHOUT_ASYNC */
|
||||
|
||||
+3
-3
@@ -906,6 +906,9 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r,
|
||||
assert(h); /* we do not allow subscriptions if no
|
||||
* GET/FETCH handler is defined */
|
||||
h(context, r, obs->session, NULL, &token, obs->query, response);
|
||||
if (COAP_RESPONSE_CLASS(response->code) > 2) {
|
||||
coap_delete_observer(r, obs->session, &token);
|
||||
}
|
||||
break;
|
||||
case COAP_DELETING_RESOURCE:
|
||||
default:
|
||||
@@ -913,9 +916,6 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r,
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: do not send response and remove observer when
|
||||
* COAP_RESPONSE_CLASS(response->hdr->code) > 2
|
||||
*/
|
||||
if (response->type == COAP_MESSAGE_CON ||
|
||||
(r->flags & COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS)) {
|
||||
obs->non_cnt = 0;
|
||||
|
||||
Reference in new issue
Block a user