From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAyfz-0003aZ-U8 for qemu-devel@nongnu.org; Mon, 21 Dec 2015 06:30:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aAyfy-0003cp-Pz for qemu-devel@nongnu.org; Mon, 21 Dec 2015 06:30:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52281) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAyfy-0003cl-KJ for qemu-devel@nongnu.org; Mon, 21 Dec 2015 06:30:50 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 4DD198E257 for ; Mon, 21 Dec 2015 11:30:50 +0000 (UTC) From: marcandre.lureau@redhat.com Date: Mon, 21 Dec 2015 12:30:39 +0100 Message-Id: <1450697444-30119-4-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1450697444-30119-1-git-send-email-marcandre.lureau@redhat.com> References: <1450697444-30119-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 3/8] ivshmem-test: leak fixes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/ivshmem-test.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c index 03c7b96..d544d5e 100644 --- a/tests/ivshmem-test.c +++ b/tests/ivshmem-test.c @@ -34,12 +34,10 @@ static void save_fn(QPCIDevice *dev, int devfn, void = *data) *pdev =3D dev; } =20 -static QPCIDevice *get_device(void) +static QPCIDevice *get_device(QPCIBus *pcibus) { QPCIDevice *dev; - QPCIBus *pcibus; =20 - pcibus =3D qpci_init_pc(); dev =3D NULL; qpci_device_foreach(pcibus, 0x1af4, 0x1110, save_fn, &dev); g_assert(dev !=3D NULL); @@ -50,6 +48,7 @@ static QPCIDevice *get_device(void) typedef struct _IVState { QTestState *qtest; void *reg_base, *mem_base; + QPCIBus *pcibus; QPCIDevice *dev; } IVState; =20 @@ -100,13 +99,20 @@ static inline void out_reg(IVState *s, enum Reg reg,= unsigned v) global_qtest =3D qtest; } =20 +static void cleanup_vm(IVState *s) +{ + g_free(s->dev); + qpci_free_pc(s->pcibus); + qtest_quit(s->qtest); +} + static void setup_vm_cmd(IVState *s, const char *cmd, bool msix) { uint64_t barsize; =20 s->qtest =3D qtest_start(cmd); - - s->dev =3D get_device(); + s->pcibus =3D qpci_init_pc(); + s->dev =3D get_device(s->pcibus); =20 /* FIXME: other bar order fails, mappings changes */ s->mem_base =3D qpci_iomap(s->dev, 2, &barsize); @@ -173,7 +179,7 @@ static void test_ivshmem_single(void) g_assert_cmpuint(data[i], =3D=3D, i); } =20 - qtest_quit(s->qtest); + cleanup_vm(s); } =20 static void test_ivshmem_pair(void) @@ -218,8 +224,8 @@ static void test_ivshmem_pair(void) g_assert_cmpuint(data[i], =3D=3D, 0x44); } =20 - qtest_quit(s1->qtest); - qtest_quit(s2->qtest); + cleanup_vm(s1); + cleanup_vm(s2); g_free(data); } =20 @@ -356,8 +362,8 @@ static void test_ivshmem_server(void) } while (ret =3D=3D 0 && g_get_monotonic_time() < end_time); g_assert_cmpuint(ret, !=3D, 0); =20 - qtest_quit(s2->qtest); - qtest_quit(s1->qtest); + cleanup_vm(s2); + cleanup_vm(s1); =20 if (qemu_write_full(thread.pipe[1], "q", 1) !=3D 1) { g_error("qemu_write_full: %s", g_strerror(errno)); @@ -395,7 +401,7 @@ static void test_ivshmem_memdev(void) setup_vm_cmd(&state, "-object memory-backend-ram,size=3D1M,id=3Dmb1" " -device ivshmem,x-memdev=3Dmb1", false); =20 - qtest_quit(state.qtest); + cleanup_vm(&state); } =20 static void cleanup(void) --=20 2.5.0