avast / avast/retdec

Bin2llvmir: leaking memory

Open
#164 1 comment 0 reactions 0 assignees View on GitHub
bug C-bin2llvmir P-run
Dominant language
C++
Stars
8.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Bin2llvmir is leaking memory while processing this input: [leak.zip](https://github.com/avast-tl/retdec/files/1700262/leak.zip).

E.g. (and many other places):
```
==5589== 1,024 bytes in 1 blocks are indirectly lost in loss record 1,303 of 1,459
==5589== at 0x4C2D52F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5589== by 0x47DEC6: retdec::dwarfparser::DwarfLineContainer::loadAndGetDie(Dwarf_Die_s*, unsigned int) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x477AE4: retdec::dwarfparser::DwarfFile::loadDIE(Dwarf_Die_s*, retdec::dwarfparser::DwarfBaseElement*&, int) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x478167: retdec::dwarfparser::DwarfFile::loadCUtree(Dwarf_Die_s*, retdec::dwarfparser::DwarfBaseElement*, int) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x478330: retdec::dwarfparser::DwarfFile::loadFileCUs() (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x4787D1: retdec::dwarfparser::DwarfFile::loadFile(std::__cxx11::basic_string, std::allocator >, retdec::fileformat::FileFormat*) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x478A85: retdec::dwarfparser::DwarfFile::DwarfFile(std::__cxx11::basic_string, std::allocator >, retdec::fileformat::FileFormat*) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x46EDC1: retdec::debugformat::DebugFormat::DebugFormat(retdec::loader::Image*, std::__cxx11::basic_string, std::allocator > const&, std::map, std::allocator > >*, retdec::demangler::CDemangler*, unsigned long long) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x422811: retdec::bin2llvmir::DebugFormatProvider::addDebugFormat(llvm::Module*, retdec::loader::Image*, std::__cxx11::basic_string, std::allocator > const&, retdec::utils::Address const&, retdec::demangler::CDemangler*) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x3E1C85: retdec::bin2llvmir::ProviderInitialization::runOnModule(llvm::Module&) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0xE62033: llvm::legacy::PassManagerImpl::run(llvm::Module&) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
==5589== by 0x325D77: _main(int, char**) (in /home/peter/retdec-github/retdec/build/install/bin/retdec-bin2llvmir)
```

**Command:**
```
valgrind --leak-check=full --show-leak-kinds=all retdec-bin2llvmir ...
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the report with leak.zip using the provided valgrind command and inspect the stack through retdec::dwarfparser::DwarfLineContainer::loadAndGetDie(), DwarfFile::loadDIE(), loadCUtree(), and loadFileCUs(). Trace the allocations reachable from retdec-bin2llvmir's debug-format initialization and verify that the reported leaks no longer appear in the valgrind results.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
reverse-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.