The one which actually saves the data is data_list.data.d.d_buf, so check it
before free rawdata_base.

This can fix a segmentation fault when prelink libqb_1.0.3:
prelink: /usr/lib/libqb.so.0.18.2: Symbol section index outside of section 
numbers

The segmentation fault happens when prelink call elf_end().

Signed-off-by: Robert Yang <liezhi.y...@windriver.com>
---
 libelf/elf_end.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 160f0b8..5280a70 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -160,14 +160,16 @@ elf_end (Elf *elf)
                   architecture doesn't require overly stringent
                   alignment the raw data buffer is the same as the
                   one used for presenting to the caller.  */
-               if (scn->data_base != scn->rawdata_base)
+               if ((scn->data_base != scn->rawdata_base)
+                   && (scn->data_list.data.d.d_buf != NULL))
                  free (scn->data_base);
 
                /* The section data is allocated if we couldn't mmap
                   the file.  Or if we had to decompress.  */
-               if (elf->map_address == NULL
+               if ((elf->map_address == NULL
                    || scn->rawdata_base == scn->zdata_base
                    || (scn->flags & ELF_F_MALLOCED) != 0)
+                   && (scn->data_list.data.d.d_buf != NULL))
                  free (scn->rawdata_base);
 
                /* Free the list of data buffers for the section.
-- 
2.7.4

Reply via email to