summaryrefslogtreecommitdiffstats
path: root/libwifi_system_iface/interface_tool.cpp
diff options
context:
space:
mode:
authorPatrik Fimml <patrikf@google.com>2019-10-01 13:04:30 +0200
committerPatrik Fimml <patrikf@google.com>2019-10-03 17:47:43 +0200
commitf8fb736b6fd012436f9d31e23416d08289ed332b (patch)
tree61adfc2809bf1eee8d4847a6566237f5e7930f06 /libwifi_system_iface/interface_tool.cpp
parent202f953f9cca885a6a220c15879be8d2243e8ae1 (diff)
downloadframeworks_opt_net_wifi-f8fb736b6fd012436f9d31e23416d08289ed332b.tar.gz
frameworks_opt_net_wifi-f8fb736b6fd012436f9d31e23416d08289ed332b.tar.bz2
frameworks_opt_net_wifi-f8fb736b6fd012436f9d31e23416d08289ed332b.zip
Fix GetFactoryMacAddress memory leak.
Previously this allocated memory and never freed it. The size is known at compile time, so we just allocate memory on the stack which simplifies error handling. Also documents behavior on error. Bug: 132705022 Test: m -j32 vts && vts-tradefed run vts-hal --skip-preconditions --module VtsHalWifiV1_3Target Change-Id: I9d806d4212d6c702717915bf25c2cde3831cd297
Diffstat (limited to 'libwifi_system_iface/interface_tool.cpp')
-rw-r--r--libwifi_system_iface/interface_tool.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/libwifi_system_iface/interface_tool.cpp b/libwifi_system_iface/interface_tool.cpp
index 261698215..17895d6ef 100644
--- a/libwifi_system_iface/interface_tool.cpp
+++ b/libwifi_system_iface/interface_tool.cpp
@@ -138,7 +138,12 @@ bool InterfaceTool::SetMacAddress(const char* if_name,
std::array<uint8_t, ETH_ALEN> InterfaceTool::GetFactoryMacAddress(const char* if_name) {
std::array<uint8_t, ETH_ALEN> paddr = {};
struct ifreq ifr;
- struct ethtool_perm_addr *epaddr;
+ struct {
+ // Allocate ETH_ALEN bytes after ethtool_perm_addr.
+ struct ethtool_perm_addr epaddr;
+ uint8_t data[ETH_ALEN];
+ } epaddr_buf;
+ struct ethtool_perm_addr* epaddr = &epaddr_buf.epaddr;
base::unique_fd sock(socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0));
if (sock.get() < 0) {
@@ -151,13 +156,6 @@ std::array<uint8_t, ETH_ALEN> InterfaceTool::GetFactoryMacAddress(const char* if
return paddr; // logging done internally
}
- epaddr = (ethtool_perm_addr*) malloc(sizeof(struct ethtool_perm_addr) + ETH_ALEN);
- if (!epaddr) {
- LOG(ERROR) << "Failed to set memory for mac address ("
- << strerror(errno) << ")";
- return paddr;
- }
-
epaddr->cmd = ETHTOOL_GPERMADDR;
epaddr->size = ETH_ALEN;
ifr.ifr_data = epaddr;