[v1,1/2] bus/vdev: fix memory leak

Message ID 20230705092511.362484-2-wenjun1.wu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series fix memory leak |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Wenjun Wu July 5, 2023, 9:25 a.m. UTC
  In hotplug usecase, devargs will be allocated in secondary process
in the function alloc_devargs. Since it will not be insert into the
devarg_list, it will have no chance to be freed.

This patch adds additional memory free for device structure member devargs
in the secondary process in rte_vdev_uninit.

Fixes: f5b2eff0847d ("bus/vdev: fix devargs after multi-process bus scan")
Cc: stable@dpdk.org

Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
---
 drivers/bus/vdev/vdev.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Chengwen Feng July 6, 2023, 12:48 a.m. UTC | #1
On 2023/7/5 17:25, Wenjun Wu wrote:
> In hotplug usecase, devargs will be allocated in secondary process
> in the function alloc_devargs. Since it will not be insert into the
> devarg_list, it will have no chance to be freed.
> 
> This patch adds additional memory free for device structure member devargs
> in the secondary process in rte_vdev_uninit.
> 
> Fixes: f5b2eff0847d ("bus/vdev: fix devargs after multi-process bus scan")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
> ---
>  drivers/bus/vdev/vdev.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
> index 7974b27295..3f4e6a1b55 100644
> --- a/drivers/bus/vdev/vdev.c
> +++ b/drivers/bus/vdev/vdev.c
> @@ -373,6 +373,11 @@ rte_vdev_uninit(const char *name)
>  
>  	TAILQ_REMOVE(&vdev_device_list, dev, next);
>  	rte_devargs_remove(dev->device.devargs);
> +	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
> +	    dev->device.devargs != NULL) {

The prerequisite is that rte_vdev_init is invoked only in main process.

Suggest more general impl:
	ret = rte_devargs_remove(dev->device.devargs);
	if (ret != 0) {
		rte_devargs_reset(dev->device.devargs);
		free(dev->device.devargs);
	}

> +		rte_devargs_reset(dev->device.devargs);
> +		free(dev->device.devargs);
> +	}
>  	free(dev);
>  
>  unlock:
>
  

Patch

diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 7974b27295..3f4e6a1b55 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -373,6 +373,11 @@  rte_vdev_uninit(const char *name)
 
 	TAILQ_REMOVE(&vdev_device_list, dev, next);
 	rte_devargs_remove(dev->device.devargs);
+	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+	    dev->device.devargs != NULL) {
+		rte_devargs_reset(dev->device.devargs);
+		free(dev->device.devargs);
+	}
 	free(dev);
 
 unlock: