> Subject: [PATCH 1/3] bus/vmbus: fix leak on device scan
> 
> Caught running ASAN.
> 
> The device name is leaked on scan.
> rte_device name field being a const, use the private vmbus struct to store the
> device name and point at it.
> 
> Fixes: 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
> Cc: sta...@dpdk.org
> 
> Signed-off-by: David Marchand <david.march...@redhat.com>
> ---
>  drivers/bus/vmbus/linux/vmbus_bus.c | 5 ++++-
>  drivers/bus/vmbus/rte_bus_vmbus.h   | 1 +
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c
> b/drivers/bus/vmbus/linux/vmbus_bus.c
> index 3c924eee14..d8eb07d398 100644
> --- a/drivers/bus/vmbus/linux/vmbus_bus.c
> +++ b/drivers/bus/vmbus/linux/vmbus_bus.c
> @@ -242,7 +242,7 @@ vmbus_scan_one(const char *name)
>               return -1;
> 
>       dev->device.bus = &rte_vmbus_bus.bus;
> -     dev->device.name = strdup(name);
> +     dev->device.name = dev->name = strdup(name);


I suggest not to add a "name" in struct rte_vmbus_device. How about defining a 
local variable in this function, like:
dev->device.name = dev_name = strdup(name);

If failed, just free(dev_name).

>       if (!dev->device.name)
>               goto error;
> 
> @@ -261,6 +261,7 @@ vmbus_scan_one(const char *name)
> 
>       /* skip non-network devices */
>       if (rte_uuid_compare(dev->class_id, vmbus_nic_uuid) != 0) {
> +             free(dev->name);
>               free(dev);
>               return 0;
>       }
> @@ -312,6 +313,7 @@ vmbus_scan_one(const char *name)
>               } else { /* already registered */
>                       VMBUS_LOG(NOTICE,
>                               "%s already registered", name);
> +                     free(dev->name);
>                       free(dev);
>               }
>               return 0;
> @@ -322,6 +324,7 @@ vmbus_scan_one(const char *name)
>  error:
>       VMBUS_LOG(DEBUG, "failed");
> 
> +     free(dev->name);
>       free(dev);
>       return -1;
>  }
> diff --git a/drivers/bus/vmbus/rte_bus_vmbus.h
> b/drivers/bus/vmbus/rte_bus_vmbus.h
> index 4cf73ce815..438eb481fc 100644
> --- a/drivers/bus/vmbus/rte_bus_vmbus.h
> +++ b/drivers/bus/vmbus/rte_bus_vmbus.h
> @@ -65,6 +65,7 @@ struct rte_vmbus_device {
>       TAILQ_ENTRY(rte_vmbus_device) next;    /**< Next probed VMBUS
> device */
>       const struct rte_vmbus_driver *driver; /**< Associated driver */
>       struct rte_device device;              /**< Inherit core device */
> +     char *name;                            /**< Device name */
>       rte_uuid_t device_id;                  /**< VMBUS device id */
>       rte_uuid_t class_id;                   /**< VMBUS device type */
>       uint32_t relid;                        /**< id for primary */
> --
> 2.23.0

Reply via email to