public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] nm: Don't leak duplicate Dwarf local names.
@ 2016-01-02 20:12 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2016-01-02 20:12 UTC (permalink / raw)
  To: elfutils-devel

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

On Wed, Dec 02, 2015 at 04:47:47PM +0100, Mark Wielaard wrote:
> Badly formed DWARF can have duplicate local names. In which case we do
> want to detect those so we don't leak the memory.

Pushed to master.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] nm: Don't leak duplicate Dwarf local names.
@ 2015-12-02 15:47 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2015-12-02 15:47 UTC (permalink / raw)
  To: elfutils-devel

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

Badly formed DWARF can have duplicate local names. In which case we do
want to detect those so we don't leak the memory.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog |  4 ++++
 src/nm.c      | 15 ++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index be7768f..ffc1b29 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
 2015-12-02  Mark Wielaard  <mjw@redhat.com>
 
+	* nm.c (get_local_names): Check for duplicates in local_root tree.
+
+2015-12-02  Mark Wielaard  <mjw@redhat.com>
+
 	* unstrip.c (struct data_list): New.
 	(new_data_list): Likewise.
 	(record_new_data): Likewise.
diff --git a/src/nm.c b/src/nm.c
index 15d9da4..69623fe 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -708,11 +708,16 @@ get_local_names (Dwarf *dbg)
 	    newp->lowpc = lowpc;
 	    newp->highpc = highpc;
 
-	    /* Since we cannot deallocate individual memory we do not test
-	       for duplicates in the tree.  This should not happen anyway.  */
-	    if (tsearch (newp, &local_root, local_compare) == NULL)
-	      error (EXIT_FAILURE, errno,
-		     gettext ("cannot create search tree"));
+	   /* Check whether a similar local_name is already in the
+	      cache.  That should not happen.  But if it does, we
+	      don't want to leak memory.  */
+	    struct local_name **tres = tsearch (newp, &local_root,
+						local_compare);
+	    if (tres == NULL)
+              error (EXIT_FAILURE, errno,
+                     gettext ("cannot create search tree"));
+	    else if (*tres != newp)
+	      free (newp);
 	  }
 	while (dwarf_siblingof (die, die) == 0);
     }
-- 
2.5.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-01-02 20:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-02 20:12 [PATCH] nm: Don't leak duplicate Dwarf local names Mark Wielaard
  -- strict thread matches above, loose matches on Subject: below --
2015-12-02 15:47 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).