diff options
author | Alan Modra <amodra@gmail.com> | 2019-12-09 20:34:49 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-12-10 09:07:29 +1030 |
commit | 20135676fc4c3912297c313b3e0d3cbd6cc402e3 (patch) | |
tree | 5073836e171a6fa7adbe05c60c23580e14defe79 | |
parent | 103ebbc35cc1975442e1e6233207d8d7b2016556 (diff) | |
download | gdb-20135676fc4c3912297c313b3e0d3cbd6cc402e3.zip gdb-20135676fc4c3912297c313b3e0d3cbd6cc402e3.tar.gz gdb-20135676fc4c3912297c313b3e0d3cbd6cc402e3.tar.bz2 |
PR24960, Memory leak from disassembler
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.
-rw-r--r-- | binutils/ChangeLog | 5 | ||||
-rw-r--r-- | binutils/objdump.c | 1 | ||||
-rw-r--r-- | include/ChangeLog | 5 | ||||
-rw-r--r-- | include/dis-asm.h | 5 | ||||
-rw-r--r-- | opcodes/ChangeLog | 5 | ||||
-rw-r--r-- | opcodes/disassemble.c | 59 |
6 files changed, 79 insertions, 1 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index b1ecef2..a194805 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,5 +1,10 @@ 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". (find_symbol_for_address): Use inf->section rather than aux->sec. (objdump_print_addr, disassemble_bytes): Likewise. diff --git a/binutils/objdump.c b/binutils/objdump.c index d48a73a..c10136e 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -2730,6 +2730,7 @@ disassemble_data (bfd *abfd) if (aux.dynrelbuf != NULL) free (aux.dynrelbuf); free (sorted_syms); + disassemble_free_target (&disasm_info); } static bfd_boolean diff --git a/include/ChangeLog b/include/ChangeLog index 7c4fcb8..681cbfa 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,5 +1,10 @@ 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. (INIT_DISASSEMBLE_INFO_NO_ARCH): Don't define. diff --git a/include/dis-asm.h b/include/dis-asm.h index c1746502..82bf4dc 100644 --- a/include/dis-asm.h +++ b/include/dis-asm.h @@ -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 *); diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 579bad8..4d22d51 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,5 +1,10 @@ 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. * disassemble.c (disassemble_init_for_target): Likewise. * bpf-dis.c: Regenerate. diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c index f131ee8..7c91997 100644 --- a/opcodes/disassemble.c +++ b/opcodes/disassemble.c @@ -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 * |