[PATCH] hw/virtio: Fix leak of host-notifier memory-region

Yajun Wu via posted 1 patch 2 years, 8 months ago
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1628732246-34765-1-git-send-email-yajunw@nvidia.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>
There is a newer version of this series
hw/virtio/vhost-user.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] hw/virtio: Fix leak of host-notifier memory-region
Posted by Yajun Wu via 2 years, 8 months ago
If call virtio_queue_set_host_notifier_mr fails, should free
host-notifier memory-region.

Signed-off-by: Yajun Wu <yajunw@nvidia.com>
---
 hw/virtio/vhost-user.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index aec6cc1..3ae5297 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1474,6 +1474,7 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev,
     g_free(name);
 
     if (virtio_queue_set_host_notifier_mr(vdev, queue_idx, &n->mr, true)) {
+        object_unparent(OBJECT(&n->mr));
         munmap(addr, page_size);
         return -1;
     }
-- 
1.8.3.1


Re: [PATCH] hw/virtio: Fix leak of host-notifier memory-region
Posted by Stefano Garzarella 2 years, 8 months ago
On Thu, Aug 12, 2021 at 04:37:26AM +0300, Yajun Wu via wrote:
>If call virtio_queue_set_host_notifier_mr fails, should free
>host-notifier memory-region.
>

We can add:
Fixes: 44866521bd ("vhost-user: support registering external host notifiers")
>Signed-off-by: Yajun Wu <yajunw@nvidia.com>
>---
> hw/virtio/vhost-user.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
>index aec6cc1..3ae5297 100644
>--- a/hw/virtio/vhost-user.c
>+++ b/hw/virtio/vhost-user.c
>@@ -1474,6 +1474,7 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev,
>     g_free(name);
>
>     if (virtio_queue_set_host_notifier_mr(vdev, queue_idx, &n->mr, true)) {
>+        object_unparent(OBJECT(&n->mr));
>         munmap(addr, page_size);
>         return -1;
>     }
>-- 
>1.8.3.1
>
>

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>