[binutils-gdb] RISC-V: Free the returned string of riscv_arch_str if we call it multiple times
Nelson Chu
nelsonc1225@sourceware.org
Tue Mar 18 04:22:58 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=433ccc440b51673ed3fce85a8dedca24f16ccab2
commit 433ccc440b51673ed3fce85a8dedca24f16ccab2
Author: Nelson Chu <nelson@rivosinc.com>
Date: Thu Mar 13 10:31:35 2025 +0800
RISC-V: Free the returned string of riscv_arch_str if we call it multiple times
The string returned from riscv_arch_str is allocated by xmalloc, so once we
called it multiple times, we should keep the newest one for the output elf
architecture attribute, but free the remaining unused strings.
Diff:
---
bfd/elfnn-riscv.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 06e99401229..873e2688ce0 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -3940,7 +3940,7 @@ static char *
riscv_merge_arch_attr_info (bfd *ibfd, char *in_arch, char *out_arch)
{
riscv_subset_t *in, *out;
- char *merged_arch_str;
+ static char *merged_arch_str = NULL;
unsigned xlen_in, xlen_out;
merged_subsets.head = NULL;
@@ -4001,6 +4001,9 @@ riscv_merge_arch_attr_info (bfd *ibfd, char *in_arch, char *out_arch)
return NULL;
}
+ /* Free the previous merged_arch_str which called xmalloc. */
+ free (merged_arch_str);
+
merged_arch_str = riscv_arch_str (ARCH_SIZE, &merged_subsets);
/* Release the subset lists. */
More information about the Binutils-cvs
mailing list