[binutils-gdb] avoid double free in _bfd_stab_section_find_nearest_line

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=283b2f9e4d4e236ba7d7142285c113f0602cf393

commit 283b2f9e4d4e236ba7d7142285c113f0602cf393
Author: Jinbao Chen <[email protected]>
Date:   Fri Aug 28 01:33:55 2026 +0800

    avoid double free in _bfd_stab_section_find_nearest_line
    
    This corrects the error return path after reloc_vector has been freed,
    and ensures this won't happen even if the wrong goto was used.
    
            PR binutils/34573
            * syms.c (_bfd_stab_section_find_nearest_line): Set reloc_vector
            to NULL after freeing it.  Correct error goto.

Diff:
---
 bfd/syms.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bfd/syms.c b/bfd/syms.c
index f48f7e66d5c..5fb8dfc0e07 100644
--- a/bfd/syms.c
+++ b/bfd/syms.c
@@ -1130,6 +1130,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
 	}
 
       free (reloc_vector);
+      reloc_vector = NULL;
 
       /* First time through this function, build a table matching
 	 function VM addresses to stabs, then sort based on starting
@@ -1186,7 +1187,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
       amt *= sizeof (struct indexentry);
       info->indextable = (struct indexentry *) bfd_malloc (amt);
       if (info->indextable == NULL)
-	goto out3;
+	goto out2;
 
       file_name = NULL;
       directory_name = NULL;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.