public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] Memory leak in process_abbrev_set
@ 2023-04-02 22:24 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-04-02 22:24 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=31991eaaeee55fbf077e5c7ed1bc5deece050933

commit 31991eaaeee55fbf077e5c7ed1bc5deece050933
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Mar 30 18:15:49 2023 +1030

    Memory leak in process_abbrev_set
    
    We may have added some abbrevs to the list before hitting an error.
    Free the list elements too.  free_abbrev_list returns list->next so we
    need to init it earlier to avoid an uninitialised memory access.
    
            * dwarf.c (process_abbrev_set): Call free_abbrev_list on errors.
            Set list->next earlier.

Diff:
---
 binutils/dwarf.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index d6fc9fe991c..d08f01cab79 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -990,6 +990,7 @@ process_abbrev_set (struct dwarf_section *section,
   list->first_abbrev = NULL;
   list->last_abbrev = NULL;
   list->raw = start;
+  list->next = NULL;
 
   while (start < end)
     {
@@ -1005,17 +1006,13 @@ process_abbrev_set (struct dwarf_section *section,
 	 the caller.  */
       if (start == end || entry == 0)
 	{
-	  list->next = NULL;
 	  list->start_of_next_abbrevs = start != end ? start : NULL;
 	  return list;
 	}
 
       READ_ULEB (tag, start, end);
       if (start == end)
-	{
-	  free (list);
-	  return NULL;
-	}
+	return free_abbrev_list (list);
 
       children = *start++;
 
@@ -1050,8 +1047,7 @@ process_abbrev_set (struct dwarf_section *section,
   /* Report the missing single zero which ends the section.  */
   error (_("%s section not zero terminated\n"), section->name);
 
-  free (list);
-  return NULL;
+  return free_abbrev_list (list);
 }
 
 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE

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

only message in thread, other threads:[~2023-04-02 22:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-02 22:24 [binutils-gdb] Memory leak in process_abbrev_set Alan Modra

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).