net: pkt: Fix leak when using shallow clone

Currently a shallow clone of a packet will bump the reference count on
all the fragments. The net_pkt_unref() function, however, only drops the
reference count on the head fragment. Fix this by only bumping the ref
count on the head buf during shallow clone.

Only bumping the ref count of head is more in line with the idea that
head buf is not responsible for the fragments of its child.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
This commit is contained in:
Andriy Gelman 2022-05-22 08:29:09 -04:00 committed by Carles Cufí
parent 275b40ef25
commit f12f9d5e95

View file

@ -1890,10 +1890,7 @@ struct net_pkt *net_pkt_shallow_clone(struct net_pkt *pkt, k_timeout_t timeout)
clone_pkt->buffer = pkt->buffer;
buf = pkt->buffer;
while (buf) {
net_pkt_frag_ref(buf);
buf = buf->frags;
}
net_pkt_frag_ref(buf);
if (pkt->buffer) {
/* The link header pointers are only usable if there is