Skip to content

Commit e180b7a

Browse files
jukkarAnas Nashif
authored andcommitted
samples: net: dtls_client: Fix memory leak in RX path
If we have not yet handled the previous RX buf, then we need to drop the latest received one, otherwise the earlier net_buf is leaked. Jira: ZEP-1169 Change-Id: I1b69e07e8b3a3b87c76d923c847dc8316c128e76 Signed-off-by: Jukka Rissanen <[email protected]> (cherry picked from commit 9527d4cdcbbf199d7d596ed18f4edb435cca4130)
1 parent 3f0e37d commit e180b7a

File tree

1 file changed

+14
-0
lines changed
  • samples/net/mbedtls_dtlsclient/src

1 file changed

+14
-0
lines changed

samples/net/mbedtls_dtlsclient/src/udp.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,22 @@ static void udp_received(struct net_context *context,
5252
ARG_UNUSED(context);
5353
ARG_UNUSED(status);
5454

55+
if (ctx->rx_nbuf) {
56+
k_sem_give(&ctx->rx_sem);
57+
k_yield();
58+
59+
if (ctx->rx_nbuf) {
60+
printk("Packet %p is still being handled, "
61+
"dropping %p\n", ctx->rx_nbuf, buf);
62+
63+
net_nbuf_unref(buf);
64+
return;
65+
}
66+
}
67+
5568
ctx->rx_nbuf = buf;
5669
k_sem_give(&ctx->rx_sem);
70+
k_yield();
5771
}
5872

5973
int udp_tx(void *context, const unsigned char *buf, size_t size)

0 commit comments

Comments
 (0)