Skip to content

Commit 3db319f

Browse files
jukkarnashif
authored andcommitted
net: tcp2: Avoid double free message
If there is an error, the net_context.c:context_sendto() will free the net_pkt, so we must not do it here. This commit fixes this error message: <err> net_pkt: *** ERROR *** pkt 0x20421908 is freed already (context_sendto():1672) Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 65a3b5a commit 3db319f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

subsys/net/ip/tcp2.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,6 @@ int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt)
14141414
NET_DBG("conn: %p Queued %zu bytes (total %zu)", conn, len,
14151415
conn->send_data_total);
14161416
pkt->buffer = NULL;
1417-
tcp_pkt_unref(pkt);
14181417

14191418
ret = tcp_send_queued_data(conn);
14201419
if (ret < 0 && ret != -ENOBUFS) {
@@ -1435,6 +1434,11 @@ int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt)
14351434
pkt->buffer = conn->send_data->buffer;
14361435
conn->send_data->buffer = NULL;
14371436
}
1437+
} else {
1438+
/* We should not free the pkt if there was an error. It will be
1439+
* freed in net_context.c:context_sendto()
1440+
*/
1441+
tcp_pkt_unref(pkt);
14381442
}
14391443
out:
14401444
k_mutex_unlock(&conn->lock);

0 commit comments

Comments
 (0)