objdump sym memory leak

Message ID Z3U4ijuJzS8lUBQo@squeak.grove.modra.org
State New
Headers
Series objdump sym memory leak |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Jan. 1, 2025, 12:43 p.m. UTC
  The sym array should be freed even with a symcount of zero.  (The
array will consist of a single NULL pointer in that case.)

	* objdump.c (dump_bfd): Free syms before replacing with
	extra_syms.  Free extra_syms after adding to syms.
  

Patch

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 478086a42c5..ecbe39e942e 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -5730,6 +5730,7 @@  dump_bfd (bfd *abfd, bool is_mainfile)
 		{
 		  if (old_symcount == 0)
 		    {
+		      free (syms);
 		      syms = extra_syms;
 		    }
 		  else
@@ -5739,6 +5740,7 @@  dump_bfd (bfd *abfd, bool is_mainfile)
 		      memcpy (syms + old_symcount,
 			      extra_syms,
 			      (symcount + 1) * sizeof (asymbol *));
+		      free (extra_syms);
 		    }
 		}