From: Nelson Chu Date: Thu, 13 Mar 2025 02:31:35 +0000 (+0800) Subject: RISC-V: Free the returned string of riscv_arch_str if we call it multiple times X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=433ccc440b51673ed3fce85a8dedca24f16ccab2;p=thirdparty%2Fbinutils-gdb.git 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 --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. */