bus: fix memleak during pci device cleanup

Message ID 20221019104923.1240394-1-kevin.laatz@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series bus: fix memleak during pci device cleanup |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed

Commit Message

Kevin Laatz Oct. 19, 2022, 10:49 a.m. UTC
  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")

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
---
 drivers/bus/pci/pci_common.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

David Marchand Oct. 19, 2022, 11:40 a.m. UTC | #1
On Wed, Oct 19, 2022 at 12:46 PM Kevin Laatz <kevin.laatz@intel.com> wrote:
>
> 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")
>
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> ---
>  drivers/bus/pci/pci_common.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
> index 7f598667fe..330a41ed12 100644
> --- a/drivers/bus/pci/pci_common.c
> +++ b/drivers/bus/pci/pci_common.c
> @@ -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.

> +                       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.


> +                       free(dev->bus_info);
> +                       dev->bus_info = NULL;
> +               }
> +
>                 free(dev);
>         }
>
> --
> 2.31.1
>
  

Patch

diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 7f598667fe..330a41ed12 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -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);
 	}