[Qemu-devel] [PATCH v2 08/30] tests: fix q35-test leaks

Marc-André Lureau posted 30 patches 8 years, 11 months ago
[Qemu-devel] [PATCH v2 08/30] tests: fix q35-test leaks
Posted by Marc-André Lureau 8 years, 11 months ago
Spotted by ASAN.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/q35-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/q35-test.c b/tests/q35-test.c
index 763fe3d6ae..e010d781e7 100644
--- a/tests/q35-test.c
+++ b/tests/q35-test.c
@@ -71,6 +71,9 @@ static void test_smram_lock(void)
     g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == false);
     smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN, true);
     g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == true);
+
+    qpci_free_pc(pcibus);
+    g_free(pcidev);
 }
 
 int main(int argc, char **argv)
-- 
2.11.0.295.gd7dffce1c.dirty


Re: [Qemu-devel] [PATCH v2 08/30] tests: fix q35-test leaks
Posted by Eric Blake 8 years, 11 months ago
On 02/21/2017 08:14 AM, Marc-André Lureau wrote:
> Spotted by ASAN.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/q35-test.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tests/q35-test.c b/tests/q35-test.c
> index 763fe3d6ae..e010d781e7 100644
> --- a/tests/q35-test.c
> +++ b/tests/q35-test.c
> @@ -71,6 +71,9 @@ static void test_smram_lock(void)
>      g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == false);
>      smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN, true);
>      g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == true);
> +
> +    qpci_free_pc(pcibus);
> +    g_free(pcidev);

I might have cleaned pcidev first (reverse order cleanup, since it was
initialized after pcibus), but I don't see any use-after-free problems
in your choice of order.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org