From: David Marchand Date: Sat, 2 Oct 2021 16:24:30 +0000 (+0200) Subject: bus/vmbus: fix leak on device scan X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c6c865d7e2e47a3a1a65a091103cca056bb073ef;p=dpdk.git bus/vmbus: fix leak on device scan Caught running ASAN. The device name was leaked on scan. rte_device name field being a const, use a local pointer and release in error path. Fixes: 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Long Li --- diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c b/drivers/bus/vmbus/linux/vmbus_bus.c index 3c924eee14..68f6cc5742 100644 --- a/drivers/bus/vmbus/linux/vmbus_bus.c +++ b/drivers/bus/vmbus/linux/vmbus_bus.c @@ -236,13 +236,14 @@ vmbus_scan_one(const char *name) char filename[PATH_MAX]; char dirname[PATH_MAX]; unsigned long tmp; + char *dev_name; dev = calloc(1, sizeof(*dev)); if (dev == NULL) return -1; dev->device.bus = &rte_vmbus_bus.bus; - dev->device.name = strdup(name); + dev->device.name = dev_name = strdup(name); if (!dev->device.name) goto error; @@ -261,6 +262,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 +314,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 +325,7 @@ vmbus_scan_one(const char *name) error: VMBUS_LOG(DEBUG, "failed"); + free(dev_name); free(dev); return -1; }