Как я могу исправить косвенные утечки (на которые жалуются GCC ASAN), не распределенные с использованием new или malloc? - PullRequest
0 голосов
/ 18 марта 2019

Я запускаю кусок кода, который выделяет память, используя std::shared_ptr<>.Однако при закрытии процесса GCC ASAN жалуется на такие вещи, как Indirect leak of 91723904 byte(s) in 383 object(s), и прямых утечек нет.

Ошибка -

Indirect leak of 91723904 byte(s) in 383 object(s) allocated from:
    #0 0x7f93658497c0 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xef7c0)
    #1 0xc0275b in __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) /usr/include/c++/8/ext/new_allocator.h:111
    #2 0xc01eaf in std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) /usr/include/c++/8/bits/alloc_traits.h:436
    #3 0xc01087 in std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> > >(std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> >&) /usr/include/c++/8/bits/allocated_ptr.h:97
    #4 0xc000d3 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::_Sp_make_shared_tag, Horizon::Zone::Game::Map*, std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) /usr/include/c++/8/bits/shared_ptr_base.h:660
    #5 0xbfeda1 in std::__shared_ptr<Horizon::Zone::Game::Map, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::_Sp_make_shared_tag, std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) /usr/include/c++/8/bits/shared_ptr_base.h:1328
    #6 0xbfd2be in std::shared_ptr<Horizon::Zone::Game::Map>::shared_ptr<std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::_Sp_make_shared_tag, std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) (/home/travis/build/horizonxyz/horizon/build/bin/Debug/zone+0xbfd2be)
    #7 0xbfb57b in std::shared_ptr<Horizon::Zone::Game::Map> std::allocate_shared<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) (/home/travis/build/horizonxyz/horizon/build/bin/Debug/zone+0xbfb57b)
    #8 0xbfa076 in std::shared_ptr<Horizon::Zone::Game::Map> std::make_shared<Horizon::Zone::Game::Map, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) /usr/include/c++/8/bits/shared_ptr.h:723
    #9 0xbf4371 in Horizon::Zone::Game::MapManager::LoadMapCache() /home/travis/build/horizonxyz/horizon/src/Server/Zone/Game/Map/MapManager.cpp:107
    #10 0xbf06f6 in Horizon::Zone::Game::MapManager::initialize() /home/travis/build/horizonxyz/horizon/src/Server/Zone/Game/Map/MapManager.cpp:49
    #11 0x42e82b in Horizon::Zone::ZoneMain::initialize_core() /home/travis/build/horizonxyz/horizon/src/Server/Zone/Zone.cpp:145
    #12 0x42f656 in main /home/travis/build/horizonxyz/horizon/src/Server/Zone/Zone.cpp:223
    #13 0x7f936372982f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Как видно выше, это выделяется с помощью shared_ptr, который не требует явного освобождения объектов.Но опять же, необходимо будет выполнить внутренний вызов из STL, чтобы удалить объект, который, по моему мнению, не происходит по окончании процесса?Или что GCC не может захватить его.

...