]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libelf: Return already gotten Elf_Data from elf_getdata_rawchunk
authorMark Wielaard <mark@klomp.org>
Fri, 1 Apr 2022 10:19:20 +0000 (12:19 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 5 Apr 2022 13:09:22 +0000 (15:09 +0200)
commit8db849976f07046d27b4217e9ebd08d5623acc4f
treee35b41026ddb34500691dfef4cb826cffce4ec51
parent4e4082be03deee515f3b6ce56eab8f2193490535
libelf: Return already gotten Elf_Data from elf_getdata_rawchunk

elf_getdata_rawchunk keeps a list of Elf_Data_Chunk to track which
Elf_Data structures have already been requested. This allows elf_end
to clean up all internal data structures and the Elf_Data d_buf if
it was malloced.

But it didn't check if a chunk was already requested earlier. This
meant that if for example dwelf_elf_gnu_build_id was called multiple
times to lookup a build-id from the phdrs a new Elf_Data_Chunk was
created. This could slowly leak memory.

So also keep track of the offset from which the size and type of
the rawdata was requested so we can return existing data if it is
requested multiple times.

Note that the current cache is a simple linked list but the chain
is normally not that long. It is normally used to get chunks from
the phdrs, and there are normally less than 10.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf_getdata_rawchunk.c
libelf/libelfP.h