eal/linux: fix memory leak in uevent handling
authorYunjian Wang <wangyunjian@huawei.com>
Sat, 23 May 2020 10:52:21 +0000 (18:52 +0800)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 20 Oct 2020 14:01:37 +0000 (16:01 +0200)
When the memory for uevent.devname is allocated in dev_uev_parse(). It
is not freed when parse the subsystem layer fails in dev_uev_parse().
Before return, it is also not freed in dev_uev_handler(). These cause a
memory leak.

Fixes: 0d0f478d0483 ("eal/linux: add uevent parse and process")
Cc: stable@dpdk.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
lib/librte_eal/linux/eal_dev.c

index 2e15762..5c0e752 100644 (file)
@@ -195,7 +195,7 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length)
        else if (!strncmp(subsystem, "vfio", 4))
                event->subsystem = EAL_DEV_EVENT_SUBSYSTEM_VFIO;
        else
-               return -1;
+               goto err;
 
        /* parse the action type */
        if (!strncmp(action, "add", 3))
@@ -203,8 +203,11 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length)
        else if (!strncmp(action, "remove", 6))
                event->type = RTE_DEV_EVENT_REMOVE;
        else
-               return -1;
+               goto err;
        return 0;
+err:
+       free(event->devname);
+       return -1;
 }
 
 static void
@@ -282,12 +285,14 @@ dev_uev_handler(__rte_unused void *param)
                        rte_spinlock_unlock(&failure_handle_lock);
                }
                rte_dev_event_callback_process(uevent.devname, uevent.type);
+               free(uevent.devname);
        }
 
        return;
 
 failure_handle_err:
        rte_spinlock_unlock(&failure_handle_lock);
+       free(uevent.devname);
 }
 
 int