[6/6] objdump: sframe: fix memory leaks

Message ID 20221207195222.1182788-7-indu.bhagat@oracle.com
State Accepted
Headers
Series Small improvements around SFrame support |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Indu Bhagat Dec. 7, 2022, 7:52 p.m. UTC
  ChangeLog:

	* binutils/objdump.c (dump_section_sframe): free up contents and
	SFrame decoder context on exit.
---
 binutils/objdump.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Comments

Nick Clifton Dec. 8, 2022, 11:14 a.m. UTC | #1
Hi Indu,

> ChangeLog:
> 
> 	* binutils/objdump.c (dump_section_sframe): free up contents and
> 	SFrame decoder context on exit.

Approved - please apply.

Cheers
   Nick
  

Patch

diff --git a/binutils/objdump.c b/binutils/objdump.c
index d95c8b68bf0..6695c5d343f 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -4871,12 +4871,18 @@  dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED,
   /* Decode the contents of the section.  */
   sfd_ctx = sframe_decode ((const char*)sframe_data, sf_size, &err);
   if (!sfd_ctx)
-    bfd_fatal (bfd_get_filename (abfd));
+    {
+      free (sframe_data);
+      bfd_fatal (bfd_get_filename (abfd));
+    }
 
   printf (_("Contents of the SFrame section %s:"),
 	  sanitize_string (sect_name));
   /* Dump the contents as text.  */
   dump_sframe (sfd_ctx, sf_vma);
+
+  free (sframe_data);
+  sframe_decoder_free (&sfd_ctx);
 }