serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
720 stars 155 forks source link

Double free after move constructor #75

Closed galjs closed 2 years ago

galjs commented 2 years ago

When creating an elfio object and then use it with std::move in the move constructor of a new elfio object, the header, segment and section pointers of the original object aren't reassigned to nullptr, thus causing them to get freed with the destructor of the original object is called. This causes the destructor of the second elfio object to throw an access violation error when trying to delete these pointers since they are already freed.

Suggested solution: Implement a custom move constructor and move assignment operator that reassign these pointers to nullptr.

OR

Replace all occurrences of new in the code with std::make_unique and replace all raw pointers with std::unique_ptrs to allow for default move construction and assignment implementations (as present today).

serge1 commented 2 years ago

Thank you for your suggestions. I am on it.

serge1 commented 2 years ago

The issue has been address by commit 24d29a2 .