Re: [PATCH 1/2] Two bug fixes in mdict_free

Simon Marchi
2025-10-23T18:26:52Z

On 10/23/25 1:17 PM, Tom Tromey wrote:
> A heap-allocated multidictionary should be freed by calling
> mdict_free. However, while this function does free the contents of
> the dictionary, it neglects to free the dictionary itself.
>
> There's also a second bug, which is that if a multidictionary is
> created with no dictionaries, gdb will crash on the first line of
> mdict_free:
>
> enum dict_type type = mdict->dictionaries[0]->vector->type;
>
> So, this patch also adds the type to struct multidictionary, avoiding
> this problem. Note that this does not increase the structure size on
> x86-64, because the new member fits into the padding.

I think you could just remove dict_vector::type and use
multidictionary::type at the single spot where dict_vector::type is
still used.

Simon