net: sockets: Release net_pkt if error during UDP recv()
If we are receiving UDP packet and if there is some error happening inside zsock_recv_dgram(), then make sure that the net_pkt received from recv_q is freed. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
65d8429d29
commit
0a47dc5918
1 changed files with 10 additions and 3 deletions
|
@ -769,7 +769,7 @@ static inline ssize_t zsock_recv_dgram(struct net_context *ctx,
|
|||
src_addr, *addrlen);
|
||||
if (rv < 0) {
|
||||
errno = -rv;
|
||||
return -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* addrlen is a value-result argument, set to actual
|
||||
|
@ -781,7 +781,7 @@ static inline ssize_t zsock_recv_dgram(struct net_context *ctx,
|
|||
*addrlen = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -792,7 +792,7 @@ static inline ssize_t zsock_recv_dgram(struct net_context *ctx,
|
|||
|
||||
if (net_pkt_read(pkt, buf, recv_len)) {
|
||||
errno = ENOBUFS;
|
||||
return -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_stats_update_tc_rx_time(net_pkt_iface(pkt),
|
||||
|
@ -807,6 +807,13 @@ static inline ssize_t zsock_recv_dgram(struct net_context *ctx,
|
|||
}
|
||||
|
||||
return recv_len;
|
||||
|
||||
fail:
|
||||
if (!(flags & ZSOCK_MSG_PEEK)) {
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline ssize_t zsock_recv_stream(struct net_context *ctx,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue