【发布时间】:2020-02-18 08:39:12
【问题描述】:
根据 LeakSanitizer,在堆栈上创建纹理会导致内存泄漏。 这是误报吗?
我在 macOS Mojave 上使用 sfml 版本 2.5.1。
main.cpp
#include <SFML/Graphics.hpp>
int main(int, char const**) {
sf::Texture texture;
}
编译
clang++ -Wall -Weffc++ -Werror -pedantic -g -fsanitize=address -fno-omit-frame-pointer -lstdc++ -lsfml-graphics main.cpp
运行
➜ test_sfml_texture ASAN_OPTIONS=detect_leaks=1 ./a.out
=================================================================
==48054==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 120 byte(s) in 1 object(s) allocated from:
#0 0x1005b1287 in wrap_calloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x61287)
#1 0x7fff7690e4eb in class_createInstance (libobjc.A.dylib:x86_64h+0x64eb)
#2 0x7fff7809cef3 in _os_object_alloc_realized (libdispatch.dylib:x86_64+0x2ef3)
#3 0x7fff780adb37 in dispatch_source_create (libdispatch.dylib:x86_64+0x13b37)
#4 0x7fff780b81eb in _dispatch_kq_poll (libdispatch.dylib:x86_64+0x1e1eb)
#5 0x7fff780b7d3a in _dispatch_kq_drain (libdispatch.dylib:x86_64+0x1dd3a)
#6 0x7fff780b72b1 in _dispatch_kq_unote_update (libdispatch.dylib:x86_64+0x1d2b1)
#7 0x7fff780ae720 in _dispatch_source_install (libdispatch.dylib:x86_64+0x14720)
#8 0x7fff780ae67c in _dispatch_source_activate (libdispatch.dylib:x86_64+0x1467c)
#9 0x7fff780a2b9a in _dispatch_lane_resume_activate (libdispatch.dylib:x86_64+0x8b9a)
#10 0x7fff713176b8 in (anonymous namespace)::RunElsewhere::instance() (SkyLight:x86_64+0x1d6b8)
#11 0x7fff71456f59 in __SLSInitialize_block_invoke (SkyLight:x86_64+0x15cf59)
#12 0x7fff7809d63c in _dispatch_client_callout (libdispatch.dylib:x86_64+0x363c)
#13 0x7fff7809ed4b in _dispatch_once_callout (libdispatch.dylib:x86_64+0x4d4b)
#14 0x7fff7130802e in CGS_CHECK_INIT (SkyLight:x86_64+0xe02e)
#15 0x7fff714ca6a0 in SLSMainDisplayID (SkyLight:x86_64+0x1d06a0)
#16 0x101288126 in sf::priv::VideoModeImpl::getDesktopMode() (libsfml-window.2.5.dylib:x86_64+0x1a126)
#17 0x101282409 in sf::priv::SFContext::SFContext(sf::priv::SFContext*) (libsfml-window.2.5.dylib:x86_64+0x14409)
#18 0x101273932 in sf::priv::GlContext::initResource() (libsfml-window.2.5.dylib:x86_64+0x5932)
#19 0x10050e482 in sf::Texture::Texture() (libsfml-graphics.2.5.dylib:x86_64+0x3e482)
#20 0x1004cce70 in main main.cpp:4
#21 0x7fff780ea3d4 in start (libdyld.dylib:x86_64+0x163d4)
系统
➜ test_sfml_texture which clang
/usr/local/opt/llvm@8/bin/clang
➜ test_sfml_texture clang++ --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm@8/bin
【问题讨论】:
标签: c++ memory-leaks sfml address-sanitizer