Skip to content

Commit

Permalink
net: kalmia: fix memory leaks
Browse files Browse the repository at this point in the history
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 protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
wenwenwang1 authored and davem330 committed Aug 18, 2019
1 parent 1eca92e commit f1472cb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/net/usb/kalmia.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
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;
}
Expand Down

0 comments on commit f1472cb

Please sign in to comment.