aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNelson Chu <nelson@rivosinc.com>2025-03-13 10:31:35 +0800
committerNelson Chu <nelson@rivosinc.com>2025-03-18 12:15:11 +0800
commit433ccc440b51673ed3fce85a8dedca24f16ccab2 (patch)
tree119a85a613c8eb377472acbc39d86251553dfe14
parent921d65b3f0751b714f9859496946e9560001b18f (diff)
downloadbinutils-433ccc440b51673ed3fce85a8dedca24f16ccab2.zip
binutils-433ccc440b51673ed3fce85a8dedca24f16ccab2.tar.gz
binutils-433ccc440b51673ed3fce85a8dedca24f16ccab2.tar.bz2
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.
-rw-r--r--bfd/elfnn-riscv.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 06e9940..873e268 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. */