[PATCH v1 4/7] bfd: fix memory leak when default-initializing an OAv2 attribute
Jan Beulich
jbeulich@suse.com
Thu Feb 5 16:49:15 GMT 2026
On 05.02.2026 17:02, Matthieu Longo wrote:
> On 05/02/2026 15:39, Jan Beulich wrote:
>> On 05.02.2026 16:18, Matthieu Longo wrote:
>>> New version using oav2_assign_value().
>>
>> Just one question:
>>
>>> --- a/bfd/elf-attrs.c
>>> +++ b/bfd/elf-attrs.c
>>> @@ -1083,33 +1083,30 @@ oav2_attr_overwrite_with_default (const struct bfd_link_info *info,
>>> {
>>> const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
>>>
>>> + union obj_attr_value_v2 default_value;
>>> + memset (&default_value, 0, sizeof (default_value));
>>
>> Why not via an initializer?
>
> I did some research because I remember that last time I had to initialize a union with zero, there was an issue somewhere.
> And I found that:
>
> {0} initializer in C or C++ for unions no longer guarantees clearing of the
> whole union (except for static storage duration initialization), it just
> initializes the first union member to zero. If initialization of the whole
> union including padding bits is desirable, use {} (valid in C23 or C++) or use
> -fzero-init-padding-bits=unions option to restore the old GCC behavior.
>
> Source: https://gcc.gnu.org/gcc-15/changes.html
>
> We don't want to make C23 a requirement. And at the same time, the code must not be broken if someone wants to use C23.
> So neither {0} nor {} would work here in my understanding.
Correct. But a dedicated initializer should work, aiui, for those being specified
to work like static storage duration initializers.
Jan
More information about the Binutils
mailing list