From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQaJ6-0004yl-5Q for qemu-devel@nongnu.org; Tue, 02 Feb 2016 07:43:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQaJ5-0001yU-88 for qemu-devel@nongnu.org; Tue, 02 Feb 2016 07:43:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46770) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQaJ5-0001yP-2q for qemu-devel@nongnu.org; Tue, 02 Feb 2016 07:43:43 -0500 From: marcandre.lureau@redhat.com Date: Tue, 2 Feb 2016 13:43:31 +0100 Message-Id: <1454417016-3913-4-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1454417016-3913-1-git-send-email-marcandre.lureau@redhat.com> References: <1454417016-3913-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] [PULL 3/8] ivshmem-test: leak fixes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: claudio.fontana@huawei.com, armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 Lureau Add a cleanup_vm() function to free QPCIDevice & QPCIBus when cleaning up the IVState. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- 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