bus: fix memleak during pci device cleanup
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.
--- drivers/bus/pci/pci_common.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/bus/pci/pci_common.c +14 -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 (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
Quoted 18 lines · Kevin Laatz
During PCI bus device cleanup some interrupt handle pointers and the
bus_infopointer 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")Signed-off-by Kevin Laatz <[email protected]>--- drivers/bus/pci/pci_common.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/bus/pci/pci_common.c +0
-0
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
PATCH v2 1/1 bus: fix memleak during pci device cleanup
In reply to Kevin LaatzDuring 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.
---
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
@@ -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
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 cleanupDuring PCI bus device cleanup some interrupt handle pointers and the
bus_infopointer 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")Signed-off-by Kevin Laatz <[email protected]>---
Quoted 25 lines · Kevin Laatz
During PCI bus device cleanup some interrupt handle pointers and the
bus_infopointer 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")Signed-off-by Kevin Laatz <[email protected]>---
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@@ -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
David Marchand
Tested-by Weiyuan LiQuoted 10 lines · David Marchand
Quoted 9 lines · Kevin Laatz
During PCI bus device cleanup some interrupt handle pointers and the
bus_infopointer 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")Signed-off-by Kevin Laatz <[email protected]>
Quoted 1 line
Reviewed-by David Marchand <[email protected]>
Applied with suggested update, thanks.
Signature · 1 line
David Marchand