Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak at FileInfo (v4.0) when analyze an executable file #951

Closed
duykhoa1310 opened this issue May 12, 2021 · 1 comment · Fixed by #984
Closed

Memory leak at FileInfo (v4.0) when analyze an executable file #951

duykhoa1310 opened this issue May 12, 2021 · 1 comment · Fixed by #984
Assignees

Comments

@duykhoa1310
Copy link

At the function PeFormat::loadResources():

////////////////////////////

			else if (type == "Icon Group")
			{
				auto iGroup = std::make_unique<ResourceIconGroup>();
				iGroup->setIconGroupID(iconGroupIDcounter);
				resource = std::move(iGroup);
				resourceTable->addResourceIconGroup(static_cast<ResourceIconGroup *>(resource.get()));
				iconGroupIDcounter++;
			}

////////////////////////////

iGroup is ResourceIconGroup class and resource is Resource class. We have ResourceIconGroup inherits from Resource class. The memory leak happen when resource is destroyed, the memory of ResourceIconGroup class is not destroyed because Resource class doesn't have a virtual destruction.

For more information, please find the Valgrind log below.
==27545== 32 bytes in 1 blocks are definitely lost in loss record 29 of 56
==27545== at 0x4C2A593: operator new(unsigned long) (vg_replace_malloc.c:344)
==27545== by 0x56F3015: __gnu_cxx::new_allocatorretdec::fileformat::ResourceIcon*::allocate(unsigned long, void const*) (new_allocator.h:111)
==27545== by 0x56F2B2B: std::allocator_traits<std::allocatorretdec::fileformat::ResourceIcon* >::allocate(std::allocatorretdec::fileformat::ResourceIcon*&, unsigned long) (alloc_traits.h:436)
==27545== by 0x56F2213: std::_Vector_base<retdec::fileformat::ResourceIcon*, std::allocatorretdec::fileformat::ResourceIcon* >::_M_allocate(unsigned long) (stl_vector.h:172)
==27545== by 0x56F14DC: void std::vector<retdec::fileformat::ResourceIcon*, std::allocatorretdec::fileformat::ResourceIcon* >::_M_realloc_insert<retdec::fileformat::ResourceIcon* const&>(__gnu_cxx::__normal_iterator<retdec::fileformat::ResourceIcon**, std::vector<retdec::fileformat::ResourceIcon*, std::allocatorretdec::fileformat::ResourceIcon* > >, retdec::fileformat::ResourceIcon* const&) (vector.tcc:406)
==27545== by 0x56F0861: std::vector<retdec::fileformat::ResourceIcon*, std::allocatorretdec::fileformat::ResourceIcon* >::push_back(retdec::fileformat::ResourceIcon* const&) (stl_vector.h:948)
==27545== by 0x5839008: retdec::fileformat::ResourceIconGroup::addIcon(retdec::fileformat::ResourceIcon*) (resource_icon_group.cpp:314)
==27545== by 0x56EF816: retdec::fileformat::ResourceTable::linkResourceIconGroups() (resource_table.cpp:799)
==27545== by 0x571948D: retdec::fileformat::PeFormat::loadResources() (pe_format.cpp:1793)
==27545== by 0x5712FCD: retdec::fileformat::PeFormat::initStructures(std::string const&) (pe_format.cpp:654)
==27545== by 0x571203E: retdec::fileformat::PeFormat::PeFormat(std::string const&, std::string const&, retdec::fileformat::LoadFlags) (pe_format.cpp:513)
==27545== by 0x566D46D: retdec::fileinfo::PeWrapper::PeWrapper(std::string const&, std::string const&, retdec::fileformat::LoadFlags) (pe_wrapper.cpp:98)

I tried to add the a virtual destruction in Resource class. Then there is no leak anymore

@HoundThe
Copy link
Member

HoundThe commented Jul 9, 2021

Thanks a lot for the nice description!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants