All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH 28/28] tests: fix virtio-blk-test leaks
Date: Tue,  7 Feb 2017 17:52:11 +0400	[thread overview]
Message-ID: <20170207135211.15870-29-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20170207135211.15870-1-marcandre.lureau@redhat.com>

Use qvirtio_pci_device_find_slot() to avoid leaking the non-hp
device. Add assert() to avoid further leaks in the future.

Use qvirtio_pci_device_free() to correctly free QVirtioPCIDevice.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/libqos/virtio-pci.c |  1 +
 tests/virtio-blk-test.c   | 14 +++++++-------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index 8a0904bbf0..7ac15c04e1 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -68,6 +68,7 @@ static void qvirtio_pci_foreach_callback(
 static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data)
 {
     QVirtioPCIDevice **vpcidev = data;
+    assert(!*vpcidev);
     *vpcidev = (QVirtioPCIDevice *)d;
 }
 
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 10a92b410a..1eee95df49 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -108,7 +108,7 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot)
 {
     QVirtioPCIDevice *dev;
 
-    dev = qvirtio_pci_device_find(bus, VIRTIO_ID_BLOCK);
+    dev = qvirtio_pci_device_find_slot(bus, VIRTIO_ID_BLOCK, slot);
     g_assert(dev != NULL);
     g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK);
     g_assert_cmphex(dev->pdev->devfn, ==, ((slot << 3) | PCI_FN));
@@ -296,7 +296,7 @@ static void pci_basic(void)
     /* End test */
     qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
     qvirtio_pci_device_disable(dev);
-    g_free(dev);
+    qvirtio_pci_device_free(dev);
     qtest_shutdown(qs);
 }
 
@@ -389,7 +389,7 @@ static void pci_indirect(void)
     /* End test */
     qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
     qvirtio_pci_device_disable(dev);
-    g_free(dev);
+    qvirtio_pci_device_free(dev);
     qtest_shutdown(qs);
 }
 
@@ -418,7 +418,7 @@ static void pci_config(void)
     g_assert_cmpint(capacity, ==, n_size / 512);
 
     qvirtio_pci_device_disable(dev);
-    g_free(dev);
+    qvirtio_pci_device_free(dev);
 
     qtest_shutdown(qs);
 }
@@ -526,7 +526,7 @@ static void pci_msix(void)
     qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
     qpci_msix_disable(dev->pdev);
     qvirtio_pci_device_disable(dev);
-    g_free(dev);
+    qvirtio_pci_device_free(dev);
     qtest_shutdown(qs);
 }
 
@@ -642,7 +642,7 @@ static void pci_idx(void)
     qvirtqueue_cleanup(dev->vdev.bus, &vqpci->vq, qs->alloc);
     qpci_msix_disable(dev->pdev);
     qvirtio_pci_device_disable(dev);
-    g_free(dev);
+    qvirtio_pci_device_free(dev);
     qtest_shutdown(qs);
 }
 
@@ -661,7 +661,7 @@ static void pci_hotplug(void)
     dev = virtio_blk_pci_init(qs->pcibus, PCI_SLOT_HP);
     g_assert(dev);
     qvirtio_pci_device_disable(dev);
-    g_free(dev);
+    qvirtio_pci_device_free(dev);
 
     /* unplug secondary disk */
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-- 
2.11.0.295.gd7dffce1c.dirty

  parent reply	other threads:[~2017-02-07 13:53 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-07 13:51 [Qemu-devel] [PATCH 00/28] Various memory leak fixes Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 01/28] qtest: fix a memory leak Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 02/28] tests: fix qmp response leak Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 03/28] tests: fix leaks in test-io-channel-command Marc-André Lureau
2017-02-07 14:02   ` Daniel P. Berrange
2017-02-07 15:02   ` Greg Kurz
2017-02-07 13:51 ` [Qemu-devel] [PATCH 04/28] timer: use an inline function for free Marc-André Lureau
2017-02-07 16:35   ` Greg Kurz
2017-02-07 13:51 ` [Qemu-devel] [PATCH 05/28] tests: fix ptimer leaks Marc-André Lureau
2017-02-07 14:38   ` Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 06/28] tests: fix endianness-test leaks Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 07/28] tests: fix q35-test leaks Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 08/28] tests: fix vhost-user-test leaks Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 09/28] tests: fix ide-test leaks Marc-André Lureau
2017-02-08 18:16   ` John Snow
2017-02-07 13:51 ` [Qemu-devel] [PATCH 10/28] tests: fix hd-geo-test leaks Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 11/28] tests: fix bios-tables-test leak Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 12/28] tests: fix ipmi-kcs-test leak Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 13/28] tests: fix ipmi-bt-test leak Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 14/28] pc: pcihp: avoid adding ACPI_PCIHP_PROP_BSEL twice Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 15/28] tests: fix eepro100-test leak Marc-André Lureau
2017-02-07 13:51 ` [Qemu-devel] [PATCH 16/28] tests: fix tco-test leaks Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 17/28] tests: fix e1000-test leak Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 18/28] tests: fix i440fx-test leaks Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 19/28] tests: fix e1000e leaks Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 20/28] tests: fix virtio-scsi-test leak Marc-André Lureau
2017-02-07 16:43   ` Greg Kurz
2017-02-07 13:52 ` [Qemu-devel] [PATCH 21/28] tests: fix virtio-9p-test leaks Marc-André Lureau
2017-02-07 16:43   ` Greg Kurz
2017-02-07 13:52 ` [Qemu-devel] [PATCH 22/28] bus: do not unref hotplug handler Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 23/28] usb: replace handle_destroy with unrealize Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 24/28] usb: release the created buses Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 25/28] tests: allows to run single test in usb-hcd-ehci-test Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 26/28] tests: fix usb-test leaks Marc-André Lureau
2017-02-07 13:52 ` [Qemu-devel] [PATCH 27/28] tests: add specialized device_find function Marc-André Lureau
2017-02-07 13:52 ` Marc-André Lureau [this message]
2017-02-07 14:50 ` [Qemu-devel] [PATCH 00/28] Various memory leak fixes no-reply

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=20170207135211.15870-29-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.