Skip to content

Commit

Permalink
Merge pull request #577 from mrdeep1/observer_fix
Browse files Browse the repository at this point in the history
Observe: Fix coap_free_context() assert when active observe
  • Loading branch information
obgm authored Feb 24, 2021
2 parents 7c54bd7 + 9de0ff3 commit 35dbc32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,16 @@ 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
context->sendqueue = NULL;
coap_retransmittimer_restart(context);
#endif

coap_delete_all_resources(context);

#ifndef WITHOUT_ASYNC
coap_delete_all_async(context);
#endif /* WITHOUT_ASYNC */
Expand Down
6 changes: 3 additions & 3 deletions src/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -914,9 +917,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;
Expand Down

0 comments on commit 35dbc32

Please sign in to comment.