net: lwm2m: cleanup observes when closing context

When a context is closed to a server, we should clean up any
existing observes along with it.  Otherwise these will try to fire
afterward.

Signed-off-by: Michael Scott <mike@foundries.io>
This commit is contained in:
Michael Scott 2019-02-18 21:51:01 -08:00 committed by Kumar Gala
commit 144ff91670

View file

@ -3824,9 +3824,22 @@ static void lwm2m_engine_service(struct k_work *work)
int lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx)
{
struct observe_node *obs, *tmp;
sys_snode_t *prev_node = NULL;
int sock_fd = client_ctx->sock_fd;
k_delayed_work_cancel(&client_ctx->retransmit_work);
/* Remove observes for this context */
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&engine_observer_list,
obs, tmp, node) {
if (obs->ctx == client_ctx) {
sys_slist_remove(&engine_observer_list, prev_node,
&obs->node);
(void)memset(obs, 0, sizeof(*obs));
} else {
prev_node = &obs->node;
}
}
lwm2m_socket_del(client_ctx);
client_ctx->sock_fd = -1;
if (sock_fd >= 0) {