This Linux kernel change "net: kalmia: fix memory leaks" is included in the Linux 4.9.192 release. This change is authored by Wenwen Wang <wenwen [at] cs.uga.edu> on Wed Aug 14 13:56:43 2019 -0500. The commit for this change in Linux stable tree is 41cc386 (patch) which is from upstream commit f1472cb. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream f1472cb.
net: kalmia: fix memory leaks [ Upstream commit f1472cb09f11ddb41d4be84f0650835cb65a9073 ] In kalmia_init_and_get_ethernet_addr(), 'usb_buf' is allocated through kmalloc(). In the following execution, if the 'status' returned by kalmia_send_init_packet() is not 0, 'usb_buf' is not deallocated, leading to memory leaks. To fix this issue, add the 'out' label to free 'usb_buf'. Signed-off-by: Wenwen Wang <email@example.com> Signed-off-by: David S. Miller <firstname.lastname@example.org> Signed-off-by: Sasha Levin <email@example.com>
There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.
drivers/net/usb/kalmia.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c index 3e37724..0c4f419 100644 --- a/drivers/net/usb/kalmia.c +++ b/drivers/net/usb/kalmia.c @@ -117,16 +117,16 @@ status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1) / sizeof(init_msg_1), usb_buf, 24); if (status != 0) - return status; + goto out; memcpy(usb_buf, init_msg_2, 12); status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2) / sizeof(init_msg_2), usb_buf, 28); if (status != 0) - return status; + goto out; memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN); - +out: kfree(usb_buf); return status; }