public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libelf: Return already gotten Elf_Data from elf_getdata_rawchunk
@ 2022-04-01 10:50 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2022-04-01 10:50 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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 | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 7fd6202b..73917f2b 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,10 @@
+2022-04-01  Mark Wielaard  <mark@klomp.org>
+
+	* libelfP.h (struct Elf_Data_Chunk): Add an int64_t offset field.
+	* elf_getdata_rawchunk.c (elf_getdata_rawchunk): Check whether the
+	requested chunk, offset, size and type, was already handed out.
+	Set new Elf_Data_Chunk offset field.
+
 2022-03-24  Mark Wielaard  <mark@klomp.org>
 
 	* elf.h: Update from glibc.
-- 
2.18.4


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-01 10:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 10:50 [PATCH] libelf: Return already gotten Elf_Data from elf_getdata_rawchunk Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).