[PATCH] x86: Fix memory leaks in tc_gen_reloc

H.J. Lu hjl.tools@gmail.com
Tue Apr 9 23:02:17 GMT 2024


Replace XNEW with bfd_xalloc to fix memory leaks in tc_gen_reloc.

	* config/tc-i386.c (tc_gen_reloc): Replace XNEW with bfd_xalloc.
---
 gas/config/tc-i386.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 502cc1b6978..122983ece79 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -17583,8 +17583,8 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
       code = BFD_RELOC_X86_64_GOTPC64;
     }
 
-  rel = XNEW (arelent);
-  rel->sym_ptr_ptr = XNEW (asymbol *);
+  rel = bfd_xalloc (stdoutput, sizeof (arelent));
+  rel->sym_ptr_ptr = bfd_xalloc (stdoutput, sizeof (asymbol *));
   *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
 
   rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
-- 
2.44.0



More information about the Binutils mailing list