sto0pkid / AutoNomic

A p2p nomic game
5 stars 0 forks source link

AddressSanitizer detecting memory leaks #10

Closed sto0pkid closed 1 year ago

sto0pkid commented 1 year ago
=================================================================
==2785==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x4e12cd in operator new(unsigned long) (/home/AutoNomic/autonomic+0x4e12cd)
    #1 0x9d8f6f in emplace_stdin() /home/AutoNomic/autonomic.cpp:787:14
    #2 0x9da980 in main /home/AutoNomic/autonomic.cpp:827:6
    #3 0x7fe602947d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09)

Direct leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x4e12cd in operator new(unsigned long) (/home/AutoNomic/autonomic+0x4e12cd)
    #1 0x9da22e in main /home/AutoNomic/autonomic.cpp:811:17
    #2 0x7fe602947d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09)

Indirect leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x4e12cd in operator new(unsigned long) (/home/AutoNomic/autonomic+0x4e12cd)
    #1 0x52e1a0 in std::__1::__libcpp_allocate(unsigned long, unsigned long) /usr/lib/llvm-11/bin/../include/c++/v1/new:253:10
    #2 0x55ae9a in std::__1::allocator<unsigned long>::allocate(unsigned long) /usr/lib/llvm-11/bin/../include/c++/v1/memory:1789:34
    #3 0x55a8b4 in std::__1::allocator_traits<std::__1::allocator<unsigned long> >::allocate(std::__1::allocator<unsigned long>&, unsigned long) /usr/lib/llvm-11/bin/../include/c++/v1/memory:1525:21
    #4 0xa0cb53 in std::__1::deque<unsigned long, std::__1::allocator<unsigned long> >::__add_back_capacity() /usr/lib/llvm-11/bin/../include/c++/v1/deque:2604:13
    #5 0xa0b532 in std::__1::deque<unsigned long, std::__1::allocator<unsigned long> >::push_back(unsigned long const&) /usr/lib/llvm-11/bin/../include/c++/v1/deque:1930:9
    #6 0xa0b33b in std::__1::stack<unsigned long, std::__1::deque<unsigned long, std::__1::allocator<unsigned long> > >::push(unsigned long const&) /usr/lib/llvm-11/bin/../include/c++/v1/stack:199:41
    #7 0xa0b131 in StreamInput::pop_x(char) /home/AutoNomic/autonomic.cpp:235:10
    #8 0xa046b0 in StreamInput::pop() /home/AutoNomic/autonomic.cpp:240:10
    #9 0x9db0a5 in main /home/AutoNomic/autonomic.cpp:836:26
    #10 0x7fe602947d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x4e12cd in operator new(unsigned long) (/home/AutoNomic/autonomic+0x4e12cd)
    #1 0x7fe602d50778 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__grow_by(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long) (/usr/lib/x86_64-linux-gnu/libc++.so.1+0x8d778)

Indirect leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x4e12cd in operator new(unsigned long) (/home/AutoNomic/autonomic+0x4e12cd)
    #1 0x52e1a0 in std::__1::__libcpp_allocate(unsigned long, unsigned long) /usr/lib/llvm-11/bin/../include/c++/v1/new:253:10
    #2 0xa169ca in std::__1::allocator<unsigned long*>::allocate(unsigned long) /usr/lib/llvm-11/bin/../include/c++/v1/memory:1789:34
    #3 0xa167c4 in std::__1::allocator_traits<std::__1::allocator<unsigned long*> >::allocate(std::__1::allocator<unsigned long*>&, unsigned long) /usr/lib/llvm-11/bin/../include/c++/v1/memory:1525:21
    #4 0xa1109d in std::__1::__split_buffer<unsigned long*, std::__1::allocator<unsigned long*>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<unsigned long*>&) /usr/lib/llvm-11/bin/../include/c++/v1/__split_buffer:318:29
    #5 0xa0cacc in std::__1::deque<unsigned long, std::__1::allocator<unsigned long> >::__add_back_capacity() /usr/lib/llvm-11/bin/../include/c++/v1/deque:2598:13
    #6 0xa0b532 in std::__1::deque<unsigned long, std::__1::allocator<unsigned long> >::push_back(unsigned long const&) /usr/lib/llvm-11/bin/../include/c++/v1/deque:1930:9
    #7 0xa0b33b in std::__1::stack<unsigned long, std::__1::deque<unsigned long, std::__1::allocator<unsigned long> > >::push(unsigned long const&) /usr/lib/llvm-11/bin/../include/c++/v1/stack:199:41
    #8 0xa0b131 in StreamInput::pop_x(char) /home/AutoNomic/autonomic.cpp:235:10
    #9 0xa046b0 in StreamInput::pop() /home/AutoNomic/autonomic.cpp:240:10
    #10 0x9db0a5 in main /home/AutoNomic/autonomic.cpp:836:26
    #11 0x7fe602947d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09)

SUMMARY: AddressSanitizer: 4360 byte(s) leaked in 5 allocation(s).
sto0pkid commented 1 year ago

Should be following some kind of general pattern to ensure we avoid this issue. Might be easy to throw in some workarounds to fix these specific occurrences, might be more difficult to rewrite things to be more conducive to avoiding the issue altogether. Unsure.

sto0pkid commented 1 year ago

It was indeed easy enough to throw in some workarounds to fix the specific occurrences, but not much has been done yet towards preventing the issue in general. Fixed these specific cases in https://github.com/sto0pkid/AutoNomic/commit/5f896b9cdad7db43fc6496f856311b5a41eeefcd