From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Garzarella Subject: [PATCH v2 2/8] vsock/virtio: free packets during the socket release Date: Fri, 10 May 2019 14:58:37 +0200 Message-ID: <20190510125843.95587-3-sgarzare__3915.04043234221$1557493172$gmane$org@redhat.com> References: <20190510125843.95587-1-sgarzare@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20190510125843.95587-1-sgarzare@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: netdev@vger.kernel.org Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Stefan Hajnoczi , "David S. Miller" List-Id: virtualization@lists.linuxfoundation.org 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 --- net/vmw_vsock/virtio_transport_common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 0248d6808755..65c8b4a23f2b 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -827,12 +827,20 @@ 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_buf *buf; struct sock *sk = &vsk->sk; bool remove_sock = true; lock_sock(sk); if (sk->sk_type == SOCK_STREAM) remove_sock = virtio_transport_close(vsk); + while (!list_empty(&vvs->rx_queue)) { + buf = list_first_entry(&vvs->rx_queue, + struct virtio_vsock_buf, list); + list_del(&buf->list); + virtio_transport_free_buf(buf); + } release_sock(sk); if (remove_sock) -- 2.20.1