Edit: This leak does not happen on Linux, so perhaps this is a MacOS Big Sur issue?
Building the following code with the following flags produces a Direct leak
. Is this a false positive or an actual leak in SDL Net?
Flags:
-g -O0 -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize=vptr
Code:
if (SDL_Init(SDL_INIT_EVENTS) < 0)
{
std::cerr << "Failed to init SDL." << std::endl;
return;
}
if (SDLNet_Init() < 0)
{
std::cerr << "Failed to init SDL Net." << std::endl;
return;
}
auto port = 8080;
IPaddress localServerIP;
if (SDLNet_ResolveHost(&localServerIP, nullptr, port) < 0)
{
std::cerr << "Failed to resolve the TCP server host:" << SDLNet_GetError() << std::endl;
return;
}
// Direct leak here...
auto tcpServerSocket = SDLNet_TCP_Open(&localServerIP);
if (!tcpServerSocket)
{
std::cerr << "Failed to open the TCP server socket: " << SDLNet_GetError() << std::endl;
return;
}
This is the detected leak error:
===========================================================
==71118==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 28 byte(s) in 1 object(s) allocated from:
#0 0x10acc12b0 in wrap_malloc (/usr/local/opt/llvm/lib/clang/11.1.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:x86_64+0x462b0)
#1 0x10abe9c47 in SDL_DYNAPI_entry (/Library/Frameworks/SDL2.framework/Versions/A/SDL2:x86_64+0xdac47)
#2 0x107c7df27 in SDLNet_TCP_Open (app:x86_64+0x10059cf27)
#3 0x1079e7b54 in Run(int, char**) (app:x86_64+0x100306b54)
#4 0x1076e46cd in main (app:x86_64+0x1000036cd)
#5 0x7fff20667620 (/usr/lib/system/libdyld.dylib:x86_64+0x15620)
SUMMARY: AddressSanitizer: 28 byte(s) leaked in 1 allocation(s).