Skip to content

Commit

Permalink
vsock/virtio: free packets during the socket release
Browse files Browse the repository at this point in the history
When the socket is released, we should free all packets
queued in the per-socket list in order to avoid a memory
leak.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Stefano Garzarella authored and David S. Miller committed May 17, 2019
1 parent 532b0f7 commit ac03046
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions net/vmw_vsock/virtio_transport_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,19 @@ static bool virtio_transport_close(struct vsock_sock *vsk)

void virtio_transport_release(struct vsock_sock *vsk)
{
struct virtio_vsock_sock *vvs = vsk->trans;
struct virtio_vsock_pkt *pkt, *tmp;
struct sock *sk = &vsk->sk;
bool remove_sock = true;

lock_sock(sk);
if (sk->sk_type == SOCK_STREAM)
remove_sock = virtio_transport_close(vsk);

list_for_each_entry_safe(pkt, tmp, &vvs->rx_queue, list) {
list_del(&pkt->list);
virtio_transport_free_pkt(pkt);
}
release_sock(sk);

if (remove_sock)
Expand Down

0 comments on commit ac03046

Please sign in to comment.