From a17193f7af2dac9cbec66481c47882824578a5f2 Mon Sep 17 00:00:00 2001 From: Aleksandr Mezin Date: Tue, 27 May 2025 12:42:36 +0300 Subject: [PATCH] Fix memory/socket leak in `UniqueId::ethernetMacAddress()` Don't jump over `close()`/`free()` --- src/unique_id.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/unique_id.cc b/src/unique_id.cc index 3106776e3a..01075cc549 100644 --- a/src/unique_id.cc +++ b/src/unique_id.cc @@ -134,7 +134,7 @@ std::string UniqueId::ethernetMacAddress() { (unsigned char)LLADDR(sdl)[3], (unsigned char)LLADDR(sdl)[4], (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[5]); - goto end; + break; } } close(sock); @@ -219,7 +219,7 @@ std::string UniqueId::ethernetMacAddress() { (unsigned char)pAdapter->Address[3], (unsigned char)pAdapter->Address[4], (unsigned char)pAdapter->Address[5]); - goto end; + break; } pAdapter = pAdapter->Next; } @@ -227,9 +227,6 @@ std::string UniqueId::ethernetMacAddress() { free(pAdapterInfo); #endif -#if defined(__linux__) || defined(__gnu_linux__) || defined(DARWIN) || defined(WIN32) -end: -#endif return std::string(reinterpret_cast(mac)); #if defined(__linux__) || defined(__gnu_linux__) || defined(DARWIN) || defined(WIN32) failed: