virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yongjun <weiyj.lk@gmail.com>
To: "Michael S . Tsirkin" <mst@redhat.com>
Cc: Wei Yongjun <weiyj.lk@gmail.com>,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org
Subject: [PATCH -next v2] virtio: fix possible memory leak in virtqueue_add()
Date: Tue,  2 Aug 2016 14:16:31 +0000	[thread overview]
Message-ID: <1470147391-20549-1-git-send-email-weiyj.lk@gmail.com> (raw)
In-Reply-To: <1470146345-19531-1-git-send-email-weiyj.lk@gmail.com>

'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@gmail.com>
---
 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;
 	}

  parent reply	other threads:[~2016-08-02 14:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-02 13:59 [PATCH -next] virtio: fix possible memory leak in virtqueue_add() Wei Yongjun
2016-08-02 14:04 ` Michael S. Tsirkin
2016-08-02 14:16 ` Wei Yongjun [this message]
2016-08-03  4:22   ` [PATCH -next v2] " Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470147391-20549-1-git-send-email-weiyj.lk@gmail.com \
    --to=weiyj.lk@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).