SDLNet_TCP_Open 直接泄漏
Direct leak in SDLNet_TCP_Open
编辑:此泄漏不会发生在 Linux,所以这可能是 MacOS Big Sur 的问题?
使用以下标志构建以下代码会生成 Direct leak
。这是 SDL Net 中的误报还是实际泄漏?
标志:
-g -O0 -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize=vptr
代码:
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;
}
这是检测到的泄漏错误:
===========================================================
==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).
在Linux上测试,看起来没有泄漏。这可能是 MacOS Big Sur 本身的问题,也可能是使用 SDLNet 时碰巧报告为泄漏的无关内容。
编辑:此泄漏不会发生在 Linux,所以这可能是 MacOS Big Sur 的问题?
使用以下标志构建以下代码会生成 Direct leak
。这是 SDL Net 中的误报还是实际泄漏?
标志:
-g -O0 -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize=vptr
代码:
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;
}
这是检测到的泄漏错误:
===========================================================
==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).
在Linux上测试,看起来没有泄漏。这可能是 MacOS Big Sur 本身的问题,也可能是使用 SDLNet 时碰巧报告为泄漏的无关内容。