]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
PR29256, memory leak in obj_elf_section_name
authorAlan Modra <amodra@gmail.com>
Fri, 17 Jun 2022 07:55:53 +0000 (17:25 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 17 Jun 2022 11:40:06 +0000 (21:10 +0930)
commit15797439805b1bb92c491b9c9a72500d93c0cb5b
treef2209bddb16dae0edb7a13ae8ee6aa4324801deb
parentd6e1d48c83b165c129cb0aa78905f7ca80a1f682
PR29256, memory leak in obj_elf_section_name

When handling section names in quotes obj_elf_section_name calls
demand_copy_C_string, which puts the name on the gas notes obstack.
Such strings aren't usually freed, since obstack_free frees all more
recently allocated objects as well as its arg.  When handling
non-quoted names, obj_elf_section_name mallocs the name.  Due to the
mix of allocation strategies it isn't possible for callers to free
names, if that was desirable.  Partially fix this by always creating
names on the obstack, which is more efficient anyway.  (You still
can't obstack_free on error paths due to the xtensa
tc_canonicalize_section_name.)  Also remove a couple of cases where
the name is dup'd for no good reason as far as I know.

PR 29256
* config/obj-elf.c (obj_elf_section_name): Create name on notes
obstack.
(obj_elf_attach_to_group): Don't strdup group name.
(obj_elf_section): Likewise.
(obj_elf_vendor_attribute): Use xmemdup0 rather than xstrndup.
gas/config/obj-elf.c