Fix potential memory leak in libelf#1337
Merged
gianlucaborello merged 1 commit intodevfrom Mar 21, 2019
Merged
Conversation
Some old versions of libelf (such as the one used in CentOS 6) are prone to memory leaks when elf_strptr() is called, under some circumstances the memory is not freed even upon correct invocation of elf_end(). Eventually we should ship our own updated version of libelf, but since people are currently welcome to build without using our bundled dependencies, it's worth fixing anyway. The fix consists in opening the file via mmap rather than reading it via allocated buffers, which is something I honestly thought libelf was already doing by default, so it was my intention to begin with. The fix went upstream in: ``` 2016-08-07 Mark Wielaard <mjw@redhat.com> * elf_compress.c (__libelf_reset_rawdata): Check scn->flags and free rawdata_base when malloced. Set ELF_F_MALLOCED for scn->flags. * elf_end.c (elf_end): Check scn->flags and free rawdata_base if malloced. * libelfP.h (struct Elf_Scn): Document flags ELF_F_MALLOCED usage. ``` valgrind memory leak: ``` ==44437== 213,655 bytes in 2 blocks are definitely lost in loss record 3 of 3 ==44437== at 0x483577F: malloc (vg_replace_malloc.c:299) ==44437== by 0x403812: __libelf_set_rawdata_wrlock (elf_getdata.c:262) ==44437== by 0x40355E: elf_strptr (elf_strptr.c:128) ```
Contributor
|
LGTM. Good catch! |
nathan-b
approved these changes
Mar 21, 2019
Contributor
Author
|
Thanks for the review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some old versions of libelf (such as the one used in CentOS 6) are prone to
memory leaks when elf_strptr() is called, under some circumstances the
memory is not freed even upon correct invocation of elf_end().
Eventually we should ship our own updated version of libelf, but since
people are currently welcome to build without using our bundled
dependencies, it's worth fixing anyway.
The fix consists in opening the file via mmap rather than reading it via
allocated buffers, which is something I honestly thought libelf was already
doing by default, so it was my intention to begin with.
The fix went upstream in:
valgrind memory leak: