usb: core: fix memory leak on port_dev_path allocation
authorColin Ian King <colin.king@canonical.com>
Wed, 3 Oct 2018 09:59:57 +0000 (10:59 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 9 Oct 2018 14:02:29 +0000 (16:02 +0200)
Currently the allocation of port_dev_path from the call to
kobject_get_path is not being kfree'd, causing a memory leak. Fix
this by kfree'ing this at the end of the function. Add an extra
error exit path to fix one of the early leaks when envp[0] fails
to be allocated.

Detected by CoverityScan, CID#1473771 ("Resource Leak")

Fixes: 201af55da8a3 ("usb: core: added uevent for over-current")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/hub.c

index bf76a3d..c6077d5 100644 (file)
@@ -5170,7 +5170,7 @@ static void port_over_current_notify(struct usb_port *port_dev)
 
        envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
        if (!envp[0])
-               return;
+               goto exit_path;
 
        envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
                        port_dev->over_current_count);
@@ -5182,6 +5182,8 @@ static void port_over_current_notify(struct usb_port *port_dev)
        kfree(envp[1]);
 exit:
        kfree(envp[0]);
+exit_path:
+       kfree(port_dev_path);
 }
 
 static void port_event(struct usb_hub *hub, int port1)