Skip to contentSkip to conversation

bus: fix memleak during pci device cleanup

PATCH Superseded Kevin Laatz 3 participants 6 messages Oct 19, 2022 – Oct 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus: fix memleak during pci device cleanup

During PCI bus device cleanup some interrupt handle pointers and the bus_info pointer are not being free'd, leading to memory leaks. This patch fixes the memory leaks by ensuring they are free'd during device cleanup on exit.

Fixes 1cab1a40ea9b ("bus: cleanup devices on shutdown")
---
 drivers/bus/pci/pci_common.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/bus/pci/pci_common.c +14 -0
index 7f598667fe..330a41ed12 100644
@@ -456,6 +456,20 @@ pci_cleanup(void)
 		}
 		dev->driver = NULL;
 		dev->device.driver = NULL;
+
+		/* free interrupt handles */
+		if (dev->intr_handle != NULL) {
+			rte_intr_instance_free(dev->intr_handle);
+			dev->intr_handle = NULL;
+			rte_intr_instance_free(dev->vfio_req_intr_handle);
+			dev->vfio_req_intr_handle = NULL;
+		}
+
+		if (dev->bus_info != NULL) {
+			free(dev->bus_info);
+			dev->bus_info = NULL;
+		}
+
 		free(dev);
 	}
 
Signature · 1 line
2.31.1
#1 lore raw
Quoted 18 lines · Kevin Laatz

During PCI bus device cleanup some interrupt handle pointers and the bus_info pointer are not being free'd, leading to memory leaks. This patch fixes the memory leaks by ensuring they are free'd during device cleanup on exit.

Fixes 1cab1a40ea9b ("bus: cleanup devices on shutdown")
---
 drivers/bus/pci/pci_common.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/bus/pci/pci_common.c +0 -0
index 7f598667fe..330a41ed12 100644

drivers/bus/pci/pci_common.c pci_cleanup(void) · line 461

Quoted 6 lines
drivers/bus/pci/pci_common.c +3 -0
@@ -456,6 +456,20 @@ pci_cleanup(void)
                }
                dev->driver = NULL;
                dev->device.driver = NULL;
+
+               /* free interrupt handles */
+               if (dev->intr_handle != NULL) {

rte_intr_instance_free already handles NULL, no need for the check.

drivers/bus/pci/pci_common.c pci_cleanup(void) · line 468

Quoted 7 lines
drivers/bus/pci/pci_common.c +7 -0
+                       rte_intr_instance_free(dev->intr_handle);
+                       dev->intr_handle = NULL;
+                       rte_intr_instance_free(dev->vfio_req_intr_handle);
+                       dev->vfio_req_intr_handle = NULL;
+               }
+
+               if (dev->bus_info != NULL) {

Idem.

Quoted 10 lines
drivers/bus/pci/pci_common.c +4 -1
+                       free(dev->bus_info);
+                       dev->bus_info = NULL;
+               }
+
                free(dev);
        }
 
--

2.31.1

Signature · 1 line
David Marchand
#2 lore raw

PATCH v2 1/1 bus: fix memleak during pci device cleanup

In reply to Kevin Laatz

During PCI bus device cleanup some interrupt handle pointers and the bus_info pointer are not being free'd, leading to memory leaks. This patch fixes the memory leaks by ensuring they are free'd during device cleanup on exit.

Fixes 1cab1a40ea9b ("bus: cleanup devices on shutdown")

---
v2: remove redundant NULL checks

---
 drivers/bus/pci/pci_common.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/bus/pci/pci_common.c +10 -0
index 7f598667fe..71cd3f59ad 100644
@@ -456,6 +456,16 @@ pci_cleanup(void)
 		}
 		dev->driver = NULL;
 		dev->device.driver = NULL;
+
+		/* free interrupt handles */
+		rte_intr_instance_free(dev->intr_handle);
+		dev->intr_handle = NULL;
+		rte_intr_instance_free(dev->vfio_req_intr_handle);
+		dev->vfio_req_intr_handle = NULL;
+
+		free(dev->bus_info);
+		dev->bus_info = NULL;
+
 		free(dev);
 	}
 
Signature · 1 line
2.31.1
Tested-by on v2 1/1
#3 lore raw
Quoted 14 lines

-----Original Message-----
From: Kevin Laatz <[email protected]>
Sent: Wednesday, October 19, 2022 8:38 PM
To: [email protected]
Cc: Laatz, Kevin <[email protected]>; Morten Brørup <[email protected]>; Richardson, Bruce <[email protected]>
Subject: [PATCH v2] bus: fix memleak during pci device cleanup

During PCI bus device cleanup some interrupt handle pointers and the bus_info pointer are not being free'd, leading to memory leaks. This patch fixes the memory leaks by ensuring they are free'd during device cleanup on exit.

Quoted 5 lines
Fixes 1cab1a40ea9b ("bus: cleanup devices on shutdown")

---

Reviewed-by on v2 1/1
#4 lore raw
In reply to Kevin Laatz
Quoted 25 lines · Kevin Laatz

During PCI bus device cleanup some interrupt handle pointers and the bus_info pointer are not being free'd, leading to memory leaks. This patch fixes the memory leaks by ensuring they are free'd during device cleanup on exit.

Fixes 1cab1a40ea9b ("bus: cleanup devices on shutdown")

---
v2: remove redundant NULL checks

---
 drivers/bus/pci/pci_common.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/bus/pci/pci_common.c +1 -0
index 7f598667fe..71cd3f59ad 100644
@@ -456,6 +456,16 @@ pci_cleanup(void)
                }
                dev->driver = NULL;
                dev->device.driver = NULL;
+

drivers/bus/pci/pci_common.c pci_cleanup(void) · line 469

Quoted 10 lines
drivers/bus/pci/pci_common.c +9 -0
+               /* free interrupt handles */
+               rte_intr_instance_free(dev->intr_handle);
+               dev->intr_handle = NULL;
+               rte_intr_instance_free(dev->vfio_req_intr_handle);
+               dev->vfio_req_intr_handle = NULL;
+
+               free(dev->bus_info);
+               dev->bus_info = NULL;
+
                free(dev);

I'll do an update when applying: here, it is better to use pci_free(dev); which was introduced at the same time bus_info was.

Quoted 5 lines
drivers/bus/pci/pci_common.c +0 -1
        }
 
--

2.31.1

Signature · 1 line
David Marchand
Tested-by Weiyuan Li
#5 lore raw
Quoted 10 lines · David Marchand
Quoted 9 lines · Kevin Laatz

During PCI bus device cleanup some interrupt handle pointers and the bus_info pointer are not being free'd, leading to memory leaks. This patch fixes the memory leaks by ensuring they are free'd during device cleanup on exit.

Fixes 1cab1a40ea9b ("bus: cleanup devices on shutdown")
Quoted 1 line

Applied with suggested update, thanks.

Signature · 1 line
David Marchand