public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] libdw: Don't leak arange if we cannot figure out which CU it belongs to.
Date: Tue, 05 Jun 2018 20:44:00 -0000	[thread overview]
Message-ID: <1528231467-2742-1-git-send-email-mark@klomp.org> (raw)

In the unlikely case that __libdw_findcu fails to find the associated
CU we would leak one arange because it wasn't linked into the arangelist
list yet. Make sure to free it immediately.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdw/ChangeLog          | 5 +++++
 libdw/dwarf_getaranges.c | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index f0ce901..661fa9d 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,10 @@
 2018-06-05  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf_getaranges (dwarf_getaranges): Free new_arange if
+	__libdw_findcu fails.
+
+2018-06-05  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf_getsrclines.c (read_srclines): Define dirarray early and
 	check whether or not it is equal to dirstack on exit/out before
 	cleanup.
diff --git a/libdw/dwarf_getaranges.c b/libdw/dwarf_getaranges.c
index 50a98cf..bff9c86 100644
--- a/libdw/dwarf_getaranges.c
+++ b/libdw/dwarf_getaranges.c
@@ -197,7 +197,12 @@ dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges, size_t *naranges)
 	  /* We store the actual CU DIE offset, not the CU header offset.  */
 	  Dwarf_CU *cu = __libdw_findcu (dbg, offset, false);
 	  if (unlikely (cu == NULL))
-	    goto fail;
+	    {
+	      /* We haven't gotten a chance to link in the new_arange
+		 into the arangelist, don't leak it.  */
+	      free (new_arange);
+	      goto fail;
+	    }
 	  new_arange->arange.offset = __libdw_first_die_off_from_cu (cu);
 
 	  new_arange->next = arangelist;
-- 
1.8.3.1

             reply	other threads:[~2018-06-05 20:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 20:44 Mark Wielaard [this message]
2018-06-08 10:08 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1528231467-2742-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).