Merge pull request #3392 from amezin/macaddr-resource-leak

Fix memory/socket leak in `UniqueId::ethernetMacAddress()`
This commit is contained in:
Ervin Hegedus 2025-06-07 13:23:46 +02:00 committed by GitHub
commit 31507404e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -134,7 +134,7 @@ std::string UniqueId::ethernetMacAddress() {
(unsigned char)LLADDR(sdl)[3], (unsigned char)LLADDR(sdl)[3],
(unsigned char)LLADDR(sdl)[4], (unsigned char)LLADDR(sdl)[4],
(unsigned char)LLADDR(sdl)[5]); (unsigned char)LLADDR(sdl)[5]);
goto end; break;
} }
} }
@ -177,7 +177,7 @@ std::string UniqueId::ethernetMacAddress() {
(unsigned char)ifr->ifr_addr.sa_data[4], (unsigned char)ifr->ifr_addr.sa_data[4],
(unsigned char)ifr->ifr_addr.sa_data[5]); (unsigned char)ifr->ifr_addr.sa_data[5]);
goto end; break;
} }
} }
close(sock); close(sock);
@ -219,7 +219,7 @@ std::string UniqueId::ethernetMacAddress() {
(unsigned char)pAdapter->Address[3], (unsigned char)pAdapter->Address[3],
(unsigned char)pAdapter->Address[4], (unsigned char)pAdapter->Address[4],
(unsigned char)pAdapter->Address[5]); (unsigned char)pAdapter->Address[5]);
goto end; break;
} }
pAdapter = pAdapter->Next; pAdapter = pAdapter->Next;
} }
@ -227,9 +227,6 @@ std::string UniqueId::ethernetMacAddress() {
free(pAdapterInfo); free(pAdapterInfo);
#endif #endif
#if defined(__linux__) || defined(__gnu_linux__) || defined(DARWIN) || defined(WIN32)
end:
#endif
return std::string(reinterpret_cast<const char *>(mac)); return std::string(reinterpret_cast<const char *>(mac));
#if defined(__linux__) || defined(__gnu_linux__) || defined(DARWIN) || defined(WIN32) #if defined(__linux__) || defined(__gnu_linux__) || defined(DARWIN) || defined(WIN32)
failed: failed: