vsock/virtio: free packets during the socket release
authorStefano Garzarella <sgarzare@redhat.com>
Fri, 17 May 2019 14:45:43 +0000 (16:45 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 17 May 2019 18:46:36 +0000 (11:46 -0700)
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>
net/vmw_vsock/virtio_transport_common.c

index 602715f..f3f3d06 100644 (file)
@@ -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)