net: lwm2m: fix message release for separate reply

In the case of a proxy server translating HTTP -> COAP (known in
the code as "separate reply"), we were leaking lwm2m_message structures.
This was due to pending objects being cleared out during the first ACK,
and no other way of finding a matching message when the follow up packet
was received.  Let's add a second match for reply to make sure we can
find our matching message resources.

NOTE: This change renames find_msg_from_pending() to find_msg() and
makes it a static function as it's only used by the lwm2m_engine.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
This commit is contained in:
Michael Scott 2017-09-05 21:03:49 -07:00 committed by Anas Nashif
commit f630857e69
2 changed files with 13 additions and 5 deletions

View file

@ -720,11 +720,12 @@ static void zoap_options_to_path(struct zoap_option *opt, int options_count,
}
}
struct lwm2m_message *find_msg_from_pending(struct zoap_pending *pending)
static struct lwm2m_message *find_msg(struct zoap_pending *pending,
struct zoap_reply *reply)
{
size_t i;
if (!pending) {
if (!pending && !reply) {
return NULL;
}
@ -732,6 +733,10 @@ struct lwm2m_message *find_msg_from_pending(struct zoap_pending *pending)
if (messages[i].ctx && messages[i].pending == pending) {
return &messages[i];
}
if (messages[i].ctx && messages[i].reply == reply) {
return &messages[i];
}
}
return NULL;
@ -2594,7 +2599,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
* is != NULL.
*/
if (pending) {
msg = find_msg_from_pending(pending);
msg = find_msg(pending, NULL);
if (msg) {
msg->pending = NULL;
}
@ -2621,6 +2626,10 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
SYS_LOG_DBG("separated response, not removing reply");
goto cleanup;
}
if (!msg) {
msg = find_msg(pending, reply);
}
}
if (reply || pending) {
@ -2704,7 +2713,7 @@ static void retransmit_request(struct k_work *work)
return;
}
msg = find_msg_from_pending(pending);
msg = find_msg(pending, NULL);
if (!msg) {
SYS_LOG_ERR("pending has no valid LwM2M message!");
return;

View file

@ -86,7 +86,6 @@ int lwm2m_get_or_create_engine_obj(struct lwm2m_engine_context *context,
u8_t *created);
/* LwM2M message functions */
struct lwm2m_message *find_msg_from_pending(struct zoap_pending *pending);
struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx);
void lwm2m_release_message(struct lwm2m_message *msg);
int lwm2m_init_message(struct lwm2m_message *msg);