Skip to content

Commit e4ce689

Browse files
Juha Heiskanennashif
authored andcommitted
net: lwm2m: Coap Pending clear update
Fixed couple possible place for leak Coap pending entry. Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no> (cherry picked from commit 3c175951383be56fa9c1451845a15b66df41ff64)
1 parent 9681716 commit e4ce689

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,21 +1326,28 @@ struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx)
13261326
return NULL;
13271327
}
13281328

1329-
void lwm2m_reset_message(struct lwm2m_message *msg, bool release)
1329+
static void lm2m_message_clear_allocations(struct lwm2m_message *msg)
13301330
{
1331-
if (!msg) {
1332-
return;
1333-
}
1334-
13351331
if (msg->pending) {
13361332
coap_pending_clear(msg->pending);
1333+
msg->pending = NULL;
13371334
}
13381335

13391336
if (msg->reply) {
13401337
/* make sure we want to clear the reply */
13411338
coap_reply_clear(msg->reply);
1339+
msg->reply = NULL;
1340+
}
1341+
}
1342+
1343+
void lwm2m_reset_message(struct lwm2m_message *msg, bool release)
1344+
{
1345+
if (!msg) {
1346+
return;
13421347
}
13431348

1349+
lm2m_message_clear_allocations(msg);
1350+
13441351
if (msg->ctx) {
13451352
sys_slist_find_and_remove(&msg->ctx->pending_sends, &msg->node);
13461353
#if defined(CONFIG_LWM2M_QUEUE_MODE_ENABLED)
@@ -1375,6 +1382,8 @@ int lwm2m_init_message(struct lwm2m_message *msg)
13751382
token = msg->token;
13761383
}
13771384

1385+
lm2m_message_clear_allocations(msg);
1386+
13781387
r = coap_packet_init(&msg->cpkt, msg->msg_data, sizeof(msg->msg_data),
13791388
COAP_VERSION_1, msg->type, tokenlen, token,
13801389
msg->code, msg->mid);
@@ -5078,6 +5087,10 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg)
50785087
msg->cpkt.data[2] = msg->mid >> 8;
50795088
msg->cpkt.data[3] = (uint8_t) msg->mid;
50805089

5090+
if (msg->pending) {
5091+
coap_pending_clear(msg->pending);
5092+
}
5093+
50815094
/* Add the packet to the pending list. */
50825095
msg->pending = coap_pending_next_unused(
50835096
msg->ctx->pendings,
@@ -5125,6 +5138,7 @@ static void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx,
51255138
msg = find_msg(pending, NULL);
51265139
if (msg == NULL) {
51275140
LOG_DBG("Orphaned pending %p.", pending);
5141+
coap_pending_clear(pending);
51285142
return;
51295143
}
51305144

0 commit comments

Comments
 (0)