public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mjw@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: [PATCH] libdwfl: Fix memory leak in dwfl_module_getsrc_file on invalid DWARF.
Date: Thu, 14 Apr 2016 22:03:20 +0200	[thread overview]
Message-ID: <1460664200-13259-1-git-send-email-mjw@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1222 bytes --]

If we allocated the match results array ourselves, then free it when
we detect invalid DWARF and return an error.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog                 | 5 +++++
 libdwfl/dwfl_module_getsrc_file.c | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 60ed700..bdfc92f 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
 2016-04-14  Mark Wielaard  <mjw@redhat.com>
 
+	* dwfl_module_getsrc_file.c (dwfl_module_getsrc_file): Free match
+	on invalid DWARF if we allocated it.
+
+2016-04-14  Mark Wielaard  <mjw@redhat.com>
+
 	* linux-proc-maps.c (proc_maps_report): Free last_file on bad file
 	mapping.
 
diff --git a/libdwfl/dwfl_module_getsrc_file.c b/libdwfl/dwfl_module_getsrc_file.c
index 21a5915..4eaaeaf 100644
--- a/libdwfl/dwfl_module_getsrc_file.c
+++ b/libdwfl/dwfl_module_getsrc_file.c
@@ -87,6 +87,8 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
 
 	  if (unlikely (line->file >= line->files->nfiles))
 	    {
+	      if (*nsrcs == 0)
+		free (match);
 	      __libdwfl_seterrno (DWFL_E (LIBDW, DWARF_E_INVALID_DWARF));
 	      return -1;
 	    }
-- 
2.5.5

             reply	other threads:[~2016-04-14 20:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-14 20:03 Mark Wielaard [this message]
2016-04-25 11:46 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=1460664200-13259-1-git-send-email-mjw@redhat.com \
    --to=mjw@redhat.com \
    --cc=elfutils-devel@lists.fedorahosted.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).