[PATCH v2] hw/s390x: Fix memory leaks after removing elements with QTAILQ_REMOVE

Thomas Huth posted 1 patch 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260511063825.53633-1-thuth@redhat.com
Maintainers: Matthew Rosato <mjrosato@linux.ibm.com>, Farhan Ali <alifm@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Cornelia Huck <cohuck@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Richard Henderson <richard.henderson@linaro.org>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>
hw/s390x/s390-pci-vfio.c | 1 +
1 file changed, 1 insertion(+)
[PATCH v2] hw/s390x: Fix memory leaks after removing elements with QTAILQ_REMOVE
Posted by Thomas Huth 2 weeks ago
From: Thomas Huth <thuth@redhat.com>

The elements that get removed with QTAILQ_REMOVE are never referenced
afterwards anymore, so the corresponding memory should get freed.

Fixes: 37fa32de70 ("s390x/pci: Honor DMA limits set by vfio")
Reviewed-by: Farhan Ali <alifm@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 v2: Drop change to hw/s390x/s390-pci-bus.c (since it needs other rework)

 hw/s390x/s390-pci-vfio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index 7c754b656da..db6de00bd28 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -101,6 +101,7 @@ void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt)
     cnt->users--;
     if (cnt->users == 0) {
         QTAILQ_REMOVE(&s->zpci_dma_limit, cnt, link);
+        g_free(cnt);
     }
 }
 
-- 
2.54.0
Re: [PATCH v2] hw/s390x: Fix memory leaks after removing elements with QTAILQ_REMOVE
Posted by Matthew Rosato 2 weeks ago
On 5/11/26 2:38 AM, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
> 
> The elements that get removed with QTAILQ_REMOVE are never referenced
> afterwards anymore, so the corresponding memory should get freed.
> 
> Fixes: 37fa32de70 ("s390x/pci: Honor DMA limits set by vfio")
> Reviewed-by: Farhan Ali <alifm@linux.ibm.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Code looks good + re-ran tests:

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Tested-by: Matthew Rosato <mjrosato@linux.ibm.com>

Thanks Thomas!

> ---
>  v2: Drop change to hw/s390x/s390-pci-bus.c (since it needs other rework)
> 
>  hw/s390x/s390-pci-vfio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
> index 7c754b656da..db6de00bd28 100644
> --- a/hw/s390x/s390-pci-vfio.c
> +++ b/hw/s390x/s390-pci-vfio.c
> @@ -101,6 +101,7 @@ void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt)
>      cnt->users--;
>      if (cnt->users == 0) {
>          QTAILQ_REMOVE(&s->zpci_dma_limit, cnt, link);
> +        g_free(cnt);
>      }
>  }
>