[binutils-gdb] avoid double free in _bfd_stab_section_find_nearest_line

Alan Modra amodra@sourceware.org
Thu Aug 27 22:59:15 GMT 2026


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

commit 283b2f9e4d4e236ba7d7142285c113f0602cf393
Author: Jinbao Chen <zkd18cjb@mail.ustc.edu.cn>
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;


More information about the Binutils-cvs mailing list