我有一个简单的程序,只能通过sdl2
创建窗口:
::SDL_Init(SDL_INIT_EVERYTHING);
auto window_ = ::SDL_CreateWindow("", 0, 0, 640, 480, ::SDL_WINDOW_OPENGL);
bool game_on = true;
while (game_on) {
::SDL_Event event;
while (::SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
game_on = false;
break;
default:
break;
}
}
}
::SDL_DestroyWindow(window_);
::SDL_Quit();
如果我使用address-sanitizer
进行编译和运行,则输出如下:
==10545==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8192 byte(s) in 2 object(s) allocated from:
#0 0x4e1838 in __interceptor_malloc (/home/andrej/Public/git/sdl_game/bin/sdl_game+0x4e1838)
#1 0x7f3eb1a61faf (<unknown module>)
SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).
如何查看address-sanitizer
检测到的内存泄漏。但是,如果我删除了最后一个字符串(:: SDL_Quit()),则此消息消失了。为什么?