gas: Use notes obstack for PowerPC symbol names
Fixes a memory leak in the PowerPC backend of GNU Assembler by using the notes obstack for symbol names.
This patch addresses a memory leak in the PowerPC configuration of GAS where allocated symbol names were not being freed. By switching the allocation mechanism from xstrndup to notes_memdup0, the symbol names are now managed by the notes obstack, ensuring they are cleaned up automatically with the rest of the gas symbol names. This change was tested on the current master branch.
In Details
The PowerPC backend for GAS (gas/config/tc-ppc.c) currently leaks memory due to xstrndup allocations for symbol names in ppc_frob_symbol(). These allocated buffers are never freed, leading to a leak for each symbol processed. This patch rectifies this by using notes_memdup0() which allocates memory on the notes obstack. This ensures that symbol names are managed and deallocated correctly alongside other gas symbol names, preventing the memory leak.
- GAS
- The GNU Assembler, part of the GNU Binutils package.
- Obstack
- An object-stack data structure that allows for efficient allocation and deallocation of many small objects.
- PowerPC
- A RISC instruction set architecture developed by Apple, IBM, and Motorola.
- ASan
- AddressSanitizer, a memory error detector for C/C++.
- Symbol name
- A human-readable identifier associated with a memory address or a variable in a program.