[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20160803072138-mutt-send-email-mst@kernel.org>
Date: Wed, 3 Aug 2016 07:22:01 +0300
From: "Michael S. Tsirkin" <mst@...hat.com>
To: Wei Yongjun <weiyj.lk@...il.com>
Cc: virtualization@...ts.linux-foundation.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH -next v2] virtio: fix possible memory leak in
virtqueue_add()
On Tue, Aug 02, 2016 at 02:16:31PM +0000, Wei Yongjun wrote:
> 'desc' is malloced in virtqueue_add() and should be freed before
> leaving from the error handling cases, otherwise it will cause
> memory leak.
>
> Signed-off-by: Wei Yongjun <weiyj.lk@...il.com>
Appliecd except I moved this to before END_USE - seems
cleaner as alloc is caller after START_USE.
> ---
> drivers/virtio/virtio_ring.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 114a0c8..e4be912 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -328,6 +328,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
> if (out_sgs)
> vq->notify(&vq->vq);
> END_USE(vq);
> + if (indirect)
> + kfree(desc);
> return -ENOSPC;
> }
Powered by blists - more mailing lists