net: tcp: Add the frag back to caller allocated net_pkt
The original fragment chain of incoming packet will be lost and leaked
in case of early error, add frag back to packet and
let the caller do unref.
Fixes #4323
Signed-off-by: june li <junelizh@foxmail.com>
diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c
index 79ad971..21c743b 100644
--- a/subsys/net/ip/tcp.c
+++ b/subsys/net/ip/tcp.c
@@ -391,6 +391,8 @@
if (pkt_allocated) {
net_pkt_unref(pkt);
+ } else {
+ pkt->frags = tail;
}
return NULL;
@@ -400,6 +402,8 @@
if (!header) {
if (pkt_allocated) {
net_pkt_unref(pkt);
+ } else {
+ pkt->frags = tail;
}
return NULL;