bus/vmbus: fix leak on device scan
authorDavid Marchand <david.marchand@redhat.com>
Sat, 2 Oct 2021 16:24:30 +0000 (18:24 +0200)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 5 Oct 2021 15:14:58 +0000 (17:14 +0200)
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 <david.marchand@redhat.com>
Acked-by: Long Li <longli@microsoft.com>
drivers/bus/vmbus/linux/vmbus_bus.c

index 3c924ee..68f6cc5 100644 (file)
@@ -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;
 }