From 504b273b857073c626be598dc1582073af9cc47b Mon Sep 17 00:00:00 2001 From: june li Date: Fri, 14 Apr 2017 10:07:02 +0800 Subject: [PATCH] net: tcp: Do buf ref when resending a segment We need to check whether buf_sent was true when resending the TCP segment, and do a buf ref if needed. If this is not done, the buf will be unref after send, which will cause unpredictable results. Change-Id: Ibd4490305de88ac6ffd04ec42bba196e57da5c10 Signed-off-by: june li --- subsys/net/ip/tcp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index c340ba6f5c2..deb4a3f295d 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -831,7 +831,10 @@ void net_tcp_ack_received(struct net_context *ctx, uint32_t ack) SYS_SLIST_FOR_EACH_CONTAINER(&ctx->tcp->sent_list, buf, sent_list) { - net_nbuf_set_buf_sent(buf, false); + if (net_nbuf_buf_sent(buf)) { + do_ref_if_needed(buf); + net_nbuf_set_buf_sent(buf, false); + } } net_tcp_send_data(ctx);