qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Alex Chen <alex.chen@huawei.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Raphael Norwitz <raphael.norwitz@nutanix.com>,
	Euler Robot <euler.robot@huawei.com>
Subject: [PULL 1/6] vhost-user-scsi: Fix memleaks in vus_proc_req()
Date: Wed, 2 Dec 2020 06:03:07 -0500	[thread overview]
Message-ID: <20201202101655.122214-2-mst@redhat.com> (raw)
In-Reply-To: <20201202101655.122214-1-mst@redhat.com>

From: Alex Chen <alex.chen@huawei.com>

The 'elem' is allocated memory in vu_queue_pop(), and its memory should be
freed in all error branches after vu_queue_pop().
In addition, in order to free the 'elem' memory outside of while(1) loop, move
the definition of 'elem' to the beginning of vus_proc_req().

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Alex Chen <alex.chen@huawei.com>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <20201125013055.34147-1-alex.chen@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 contrib/vhost-user-scsi/vhost-user-scsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index 0f9ba4b2a2..4639440a70 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -232,6 +232,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
     VugDev *gdev;
     VusDev *vdev_scsi;
     VuVirtq *vq;
+    VuVirtqElement *elem = NULL;
 
     assert(vu_dev);
 
@@ -248,7 +249,6 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
     g_debug("Got kicked on vq[%d]@%p", idx, vq);
 
     while (1) {
-        VuVirtqElement *elem;
         VirtIOSCSICmdReq *req;
         VirtIOSCSICmdResp *rsp;
 
@@ -288,6 +288,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx)
 
         free(elem);
     }
+    free(elem);
 }
 
 static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started)
-- 
MST



  reply	other threads:[~2020-12-02 11:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 11:03 [PULL 0/6] pc,vhost: fixes Michael S. Tsirkin
2020-12-02 11:03 ` Michael S. Tsirkin [this message]
2020-12-02 11:03 ` [PULL 2/6] memory: Rename memory_region_notify_one to memory_region_notify_iommu_one Michael S. Tsirkin
2020-12-02 11:03 ` [PULL 3/6] memory: Add IOMMUTLBEvent Michael S. Tsirkin
2020-12-02 11:03 ` [PULL 4/6] memory: Add IOMMU_NOTIFIER_DEVIOTLB_UNMAP IOMMUTLBNotificationType Michael S. Tsirkin
2020-12-02 11:03 ` [PULL 5/6] intel_iommu: Skip page walking on device iotlb invalidations Michael S. Tsirkin
2020-12-02 11:03 ` [PULL 6/6] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type Michael S. Tsirkin
2020-12-03 10:20 ` [PULL 0/6] pc,vhost: fixes Peter Maydell
2020-12-03 10:58   ` Michael S. Tsirkin
2020-12-03 11:02     ` Peter Maydell
2020-12-03 11:57       ` Peter Maydell

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=20201202101655.122214-2-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=alex.chen@huawei.com \
    --cc=euler.robot@huawei.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    /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).