net: kalmia: fix memory leaks [Linux 4.19.72]

This Linux kernel change "net: kalmia: fix memory leaks" is included in the Linux 4.19.72 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 4fcb9b3 (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 <wenwen@cs.uga.edu>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>

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 bd2ba36..0cc6993 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, ARRAY_SIZE(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, ARRAY_SIZE(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;
 }

Leave a Reply

Your email address will not be published. Required fields are marked *