Skip to content

Commit 22099d1

Browse files
jukkarAnas Nashif
authored andcommitted
samples: net: dtls_client: Fix mem leak in error path
We need to unref the net_buf in error path in RX and TX. Jira: ZEP-1169 Change-Id: Icb6d43cb6b7411a5135ea09c6ae96742566fafc4 Signed-off-by: Jukka Rissanen <[email protected]> (cherry picked from commit 22ddc4419c6d7823cd530a5d5fcd1d508add4a50)
1 parent e180b7a commit 22099d1

File tree

1 file changed

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

1 file changed

+3
-0
lines changed

samples/net/mbedtls_dtlsclient/src/udp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
8989
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
9090
if (!rc) {
9191
printk("cannot write buf\n");
92+
net_nbuf_unref(send_buf);
9293
return -EIO;
9394
}
9495

@@ -121,6 +122,8 @@ int udp_rx(void *context, unsigned char *buf, size_t size)
121122

122123
read_bytes = net_nbuf_appdatalen(ctx->rx_nbuf);
123124
if (read_bytes > size) {
125+
net_nbuf_unref(ctx->rx_nbuf);
126+
ctx->rx_nbuf = NULL;
124127
return -ENOMEM;
125128
}
126129

0 commit comments

Comments
 (0)