Skip to contentSkip to conversation

hw/s390x: Fix memory leaks after removing elements with QTAILQ_REMOVE

PATCH In review Thomas Huth 3 participants 3 messages May 11 – May 29

lore
Share & tools
lore
#0 lore raw

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

From: Thomas Huth <[email protected]>

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")

---
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(+)
hw/s390x/s390-pci-vfio.c +1 -0
index 7c754b656da..db6de00bd28 100644
@@ -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);
     }
 }
 
Signature · 1 line
2.54.0
Reviewed-by Tested-by on v2 1/1
#1 lore raw
Quoted 8 lines · Thomas Huth

From: Thomas Huth <[email protected]>

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")

Code looks good + re-ran tests:

Thanks Thomas!

Quoted 18 lines

---
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(+)
hw/s390x/s390-pci-vfio.c +1 -0
index 7c754b656da..db6de00bd28 100644
@@ -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 lore raw
In reply to Thomas Huth
Quoted 19 lines · Thomas Huth

From: Thomas Huth <[email protected]>

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")

---
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(+)
hw/s390x/s390-pci-vfio.c +0 -0
index 7c754b656da..db6de00bd28 100644

hw/s390x/s390-pci-vfio.c void s390_pci_end_dma_count(S390pciState *s, S390PCIDMACount *cnt) · line 107

Quoted 7 lines
hw/s390x/s390-pci-vfio.c +1 -0
@@ -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);
     }
 }
 

Thanks, queued to s390-next.