diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2016-05-05 16:53:35 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2016-06-20 11:44:12 +0100 |
commit | f1d3b99154138741161fc52f5a8c373bf71613c6 (patch) | |
tree | 9b8dc89292f0f64c6151601192a12c0805bc3047 /tests | |
parent | c75f4c061bacad0c41708bf17d526fac72314ad0 (diff) | |
download | qemu-f1d3b99154138741161fc52f5a8c373bf71613c6.zip qemu-f1d3b99154138741161fc52f5a8c373bf71613c6.tar.gz qemu-f1d3b99154138741161fc52f5a8c373bf71613c6.tar.bz2 |
libqos: add qvirtqueue_cleanup()
qvirtqueue_setup() allocates the vring and virtqueue state. So far
there has been no function to free it. Callers have been using
guest_free() for the vring but forgot to free the QVirtQueue state.
This patch solves the memory leak by introducing qvirtqueue_cleanup().
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libqos/virtio-mmio.c | 8 | ||||
-rw-r--r-- | tests/libqos/virtio-pci.c | 10 | ||||
-rw-r--r-- | tests/libqos/virtio.c | 6 | ||||
-rw-r--r-- | tests/libqos/virtio.h | 5 | ||||
-rw-r--r-- | tests/virtio-blk-test.c | 10 | ||||
-rw-r--r-- | tests/virtio-net-test.c | 2 | ||||
-rw-r--r-- | tests/virtio-scsi-test.c | 2 |
7 files changed, 36 insertions, 7 deletions
diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c index ccb92d9..0cab38f 100644 --- a/tests/libqos/virtio-mmio.c +++ b/tests/libqos/virtio-mmio.c @@ -154,6 +154,13 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d, return vq; } +static void qvirtio_mmio_virtqueue_cleanup(QVirtQueue *vq, + QGuestAllocator *alloc) +{ + guest_free(alloc, vq->desc); + g_free(vq); +} + static void qvirtio_mmio_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq) { QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; @@ -176,6 +183,7 @@ const QVirtioBus qvirtio_mmio = { .get_queue_size = qvirtio_mmio_get_queue_size, .set_queue_address = qvirtio_mmio_set_queue_address, .virtqueue_setup = qvirtio_mmio_virtqueue_setup, + .virtqueue_cleanup = qvirtio_mmio_virtqueue_cleanup, .virtqueue_kick = qvirtio_mmio_virtqueue_kick, }; diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 3b2b59b..18b92b9 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -235,6 +235,15 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, return &vqpci->vq; } +static void qvirtio_pci_virtqueue_cleanup(QVirtQueue *vq, + QGuestAllocator *alloc) +{ + QVirtQueuePCI *vqpci = container_of(vq, QVirtQueuePCI, vq); + + guest_free(alloc, vq->desc); + g_free(vqpci); +} + static void qvirtio_pci_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; @@ -257,6 +266,7 @@ const QVirtioBus qvirtio_pci = { .get_queue_size = qvirtio_pci_get_queue_size, .set_queue_address = qvirtio_pci_set_queue_address, .virtqueue_setup = qvirtio_pci_virtqueue_setup, + .virtqueue_cleanup = qvirtio_pci_virtqueue_cleanup, .virtqueue_kick = qvirtio_pci_virtqueue_kick, }; diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index f79d2d1..d8c2970 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -54,6 +54,12 @@ QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d, return bus->virtqueue_setup(d, alloc, index); } +void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq, + QGuestAllocator *alloc) +{ + return bus->virtqueue_cleanup(vq, alloc); +} + void qvirtio_reset(const QVirtioBus *bus, QVirtioDevice *d) { bus->set_status(d, 0); diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index c73fd8c..0250842 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -79,6 +79,9 @@ typedef struct QVirtioBus { QVirtQueue *(*virtqueue_setup)(QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index); + /* Free virtqueue resources */ + void (*virtqueue_cleanup)(QVirtQueue *vq, QGuestAllocator *alloc); + /* Notify changes in virtqueue */ void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq); } QVirtioBus; @@ -118,6 +121,8 @@ void qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d, gint64 timeout_us); QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index); +void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq, + QGuestAllocator *alloc); void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr); QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 9d27be5..4ab14d5 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -298,7 +298,7 @@ static void pci_basic(void) (uint64_t)(uintptr_t)addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qvirtio_pci_device_disable(dev); g_free(dev); @@ -401,7 +401,7 @@ static void pci_indirect(void) guest_free(alloc, req_addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qvirtio_pci_device_disable(dev); g_free(dev); @@ -552,7 +552,7 @@ static void pci_msix(void) guest_free(alloc, req_addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); @@ -679,7 +679,7 @@ static void pci_idx(void) guest_free(alloc, req_addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); @@ -745,7 +745,7 @@ static void mmio_basic(void) g_assert_cmpint(capacity, ==, n_size / 512); /* End test */ - guest_free(alloc, vq->desc); + qvirtqueue_cleanup(&qvirtio_mmio, vq, alloc); generic_alloc_uninit(alloc); g_free(dev); test_end(); diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index 1712450..0d2c63f 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -229,7 +229,7 @@ static void pci_basic(gconstpointer data) /* End test */ close(sv[0]); - guest_free(alloc, tx->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &tx->vq, alloc); pc_alloc_uninit(alloc); qvirtio_pci_device_disable(dev); g_free(dev); diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 3938163..cbe5dcc 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -58,7 +58,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs) int i; for (i = 0; i < vs->num_queues + 2; i++) { - guest_free(vs->alloc, vs->vq[i]->desc); + qvirtqueue_cleanup(&qvirtio_pci, vs->vq[i], vs->alloc); } pc_alloc_uninit(vs->alloc); qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev)); |