提交 bf7f547e 编写于 作者: C Colin Ian King 提交者: Greg Kroah-Hartman

usb: core: fix memory leak on port_dev_path allocation

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: 201af55d ("usb: core: added uevent for over-current")
Signed-off-by: NColin Ian King <colin.king@canonical.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 6503016e
...@@ -5170,7 +5170,7 @@ static void port_over_current_notify(struct usb_port *port_dev) ...@@ -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); envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
if (!envp[0]) if (!envp[0])
return; goto exit_path;
envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u", envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
port_dev->over_current_count); port_dev->over_current_count);
...@@ -5182,6 +5182,8 @@ static void port_over_current_notify(struct usb_port *port_dev) ...@@ -5182,6 +5182,8 @@ static void port_over_current_notify(struct usb_port *port_dev)
kfree(envp[1]); kfree(envp[1]);
exit: exit:
kfree(envp[0]); kfree(envp[0]);
exit_path:
kfree(port_dev_path);
} }
static void port_event(struct usb_hub *hub, int port1) static void port_event(struct usb_hub *hub, int port1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册