PR24960, Memory leak from disassembler
authorAlan Modra <amodra@gmail.com>
Mon, 9 Dec 2019 10:04:49 +0000 (20:34 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 9 Dec 2019 22:37:29 +0000 (09:07 +1030)
PR 24960
include/
* dis-asm.h (disassemble_free_target): Declare.
opcodes/
* disassemble.c (disassemble_free_target): New function.
binutils/
* objdump.c (disassemble_data): Call disassemble_free_target.

binutils/ChangeLog
binutils/objdump.c
include/ChangeLog
include/dis-asm.h
opcodes/ChangeLog
opcodes/disassemble.c

index b1ecef23d4319bcb994c68b55fa338e7ee889bfc..a19480535205738a248a4ebb4b875f9c024f3dc2 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-10  Alan Modra  <amodra@gmail.com>
+
+       PR 24960
+       * objdump.c (disassemble_data): Call disassemble_free_target.
+
 2019-12-10  Alan Modra  <amodra@gmail.com>
 
        * objdump.c (struct objdump_disasm_info): Delete "sec".
index d48a73ac4a7b53ba1d8aedcc645fda13e23f2394..c10136edc3141ab40079dc58445fcb7c21e6bb08 100644 (file)
@@ -2730,6 +2730,7 @@ disassemble_data (bfd *abfd)
   if (aux.dynrelbuf != NULL)
     free (aux.dynrelbuf);
   free (sorted_syms);
+  disassemble_free_target (&disasm_info);
 }
 \f
 static bfd_boolean
index 7c4fcb82e2d54edc944bf86045ed4d5c317b1aac..681cbfa837e017b05135fb9d34f4b528034b13ed 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-10  Alan Modra  <amodra@gmail.com>
+
+       PR 24960
+       * dis-asm.h (disassemble_free_target): Declare.
+
 2019-12-10  Alan Modra  <amodra@gmail.com>
 
        * dis-asm.h (struct disassemble_info): Delete insn_sets.
index c1746502ca2de39e6936cf117d26f2f7f4aba827..82bf4dc942bc1a034fea13113a5a993db48dbdea 100644 (file)
@@ -325,7 +325,10 @@ extern disassembler_ftype disassembler (enum bfd_architecture arc,
 
 /* Amend the disassemble_info structure as necessary for the target architecture.
    Should only be called after initialising the info->arch field.  */
-extern void disassemble_init_for_target (struct disassemble_info * dinfo);
+extern void disassemble_init_for_target (struct disassemble_info *);
+
+/* Tidy any memory allocated by targets, such as info->private_data.  */
+extern void disassemble_free_target (struct disassemble_info *);
 
 /* Document any target specific options available from the disassembler.  */
 extern void disassembler_usage (FILE *);
index 579bad868b5866ac419ed061da29f26989ab4611..4d22d51178626706f3d7c01701bc9fb932b15986 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-10  Alan Modra  <amodra@gmail.com>
+
+       PR 24960
+       * disassemble.c (disassemble_free_target): New function.
+
 2019-12-10  Alan Modra  <amodra@gmail.com>
 
        * cgen-dis.in (print_insn_@arch@): Replace insn_sets with private_data.
index f131ee8520940d38949febae163b94716922796f..7c919972ee250a553532062de024ffd2556c85e1 100644 (file)
@@ -716,6 +716,65 @@ disassemble_init_for_target (struct disassemble_info * info)
     }
 }
 
+void
+disassemble_free_target (struct disassemble_info *info)
+{
+  if (info == NULL)
+    return;
+
+  switch (info->arch)
+    {
+    default:
+      return;
+
+#ifdef ARCH_bpf
+    case bfd_arch_bpf:
+#endif
+#ifdef ARCH_m32c
+    case bfd_arch_m32c:
+#endif
+#if defined ARCH_bpf || defined ARCH_m32c
+      if (info->private_data)
+       {
+         CGEN_BITSET *mask = info->private_data;
+         free (mask->bits);
+       }
+      break;
+#endif
+
+#ifdef ARCH_arc
+    case bfd_arch_arc:
+      break;
+#endif
+#ifdef ARCH_cris
+    case bfd_arch_cris:
+      break;
+#endif
+#ifdef ARCH_mmix
+    case bfd_arch_mmix:
+      break;
+#endif
+#ifdef ARCH_nfp
+    case bfd_arch_nfp:
+      break;
+#endif
+#ifdef ARCH_powerpc
+    case bfd_arch_powerpc:
+      break;
+#endif
+#ifdef ARCH_riscv
+    case bfd_arch_riscv:
+      break;
+#endif
+#ifdef ARCH_rs6000
+    case bfd_arch_rs6000:
+      break;
+#endif
+    }
+
+  free (info->private_data);
+}
+
 /* Remove whitespace and consecutive commas from OPTIONS.  */
 
 char *