hw/virtio: freeing leaked memory from vhost_svq_get_buf in vhost_svq_poll
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 28 Mar 2024 10:20:52 +0000 (14:20 +0400)
committerMarc-André Lureau <marcandre.lureau@redhat.com>
Wed, 2 Oct 2024 12:14:29 +0000 (16:14 +0400)
vhost_svq_get_buf() may return a VirtQueueElement that should be freed.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eugenio Pérez <eperezma@redhat.com>
hw/virtio/vhost-shadow-virtqueue.c

index 3b2beaea24bd4991a32ee31cbdc2bf282c1cc628..37aca8b43186d32d6a6b7ba6cdd61ea2adca32fe 100644 (file)
@@ -414,6 +414,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *svq,
     return i;
 }
 
+G_GNUC_WARN_UNUSED_RESULT
 static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
                                            uint32_t *len)
 {
@@ -528,6 +529,7 @@ size_t vhost_svq_poll(VhostShadowVirtqueue *svq, size_t num)
     size_t len = 0;
 
     while (num--) {
+        g_autofree VirtQueueElement *elem = NULL;
         int64_t start_us = g_get_monotonic_time();
         uint32_t r = 0;
 
@@ -541,7 +543,7 @@ size_t vhost_svq_poll(VhostShadowVirtqueue *svq, size_t num)
             }
         } while (true);
 
-        vhost_svq_get_buf(svq, &r);
+        elem = vhost_svq_get_buf(svq, &r);
         len += r;
     }