libelf: Fix memory leak in elf_compress for mmapped ELF files.
authorMark Wielaard <mjw@redhat.com>
Sun, 7 Aug 2016 20:13:46 +0000 (22:13 +0200)
committerMark Wielaard <mjw@redhat.com>
Mon, 15 Aug 2016 07:58:12 +0000 (09:58 +0200)
commite93f2d801fccbe5a4ffd71f07baed66453b8a56c
treefaf2178368ee667d7d94846f0ad58a5ffd8749f6
parent6ff6c215bfa4153874751cdc0bae26acfbba4a81
libelf: Fix memory leak in elf_compress for mmapped ELF files.

The testcase added to run-strip-reloc.sh for strip-compressed.o showed
a memory leak when ran under valgrind (configure --enable-valgrind).

For a mmapped ELF file when existing section data was compressed
elf_end would fail to release the new compressed data buffer assigned
to rawdata_base. For non-mapped files rawdata_base is always freed.
For decompressed data rawdata_base is released together with zdata_base.

Use the Elf_Scn flag ELF_T_MALLOCED to track whether rawdata_base
points to malloced memory and free it in elf_end even for mmapped
ELF files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/elf_compress.c
libelf/elf_end.c
libelf/libelfP.h