[PATCH vkd3d v5 5/8] vkd3d-shader/hlsl: Properly free parse_variable_def memory.
Zebediah Figura
zfigura at codeweavers.com
Mon Mar 14 11:04:01 CDT 2022
On 3/14/22 08:03, Giovanni Mascellani wrote:
> Hi,
>
> Il 10/03/22 16:14, Francisco Casas ha scritto:
>> Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
>> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
>>
>> ---
>> v5:
>> - No changes from v4.
>>
>> Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
>> ---
>> libs/vkd3d-shader/hlsl.y | 32 ++++++++++++++++++++++----------
>> 1 file changed, 22 insertions(+), 10 deletions(-)
>>
>> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
>> index 34b4a8bb..bbdc1493 100644
>> --- a/libs/vkd3d-shader/hlsl.y
>> +++ b/libs/vkd3d-shader/hlsl.y
>> @@ -668,6 +668,15 @@ static struct hlsl_type
>> *apply_type_modifiers(struct hlsl_ctx *ctx, struct hlsl_
>> return new_type;
>> }
>> +static void free_parse_variable_def(struct parse_variable_def *v)
>> +{
>> + free_parse_initializer(&v->initializer);
>> + vkd3d_free(v->arrays.sizes);
>> + vkd3d_free(v->name);
>> + vkd3d_free((void *)v->semantic.name);
>> + vkd3d_free(v);
>> +}
>> +
>> static struct list *gen_struct_fields(struct hlsl_ctx *ctx, struct
>> hlsl_type *type, struct list *fields)
>> {
>> struct parse_variable_def *v, *v_next;
>> @@ -685,13 +694,14 @@ static struct list *gen_struct_fields(struct
>> hlsl_ctx *ctx, struct hlsl_type *ty
>> if (!(field = hlsl_alloc(ctx, sizeof(*field))))
>> {
>> - vkd3d_free(v);
>> + free_parse_variable_def(v);
>> return list;
>> }
>
> I guess it's better than nothing, but you're still leaking stuff for
> later entries in "fields", aren't you?
>
>> field->type = type;
>> for (i = 0; i < v->arrays.count; ++i)
>> field->type = hlsl_new_array_type(ctx, field->type,
>> v->arrays.sizes[i]);
>> + vkd3d_free(v->arrays.sizes);
>> field->loc = v->loc;
>> field->name = v->name;
>> field->semantic = v->semantic;
>> @@ -719,7 +729,10 @@ static bool add_typedef(struct hlsl_ctx *ctx,
>> DWORD modifiers, struct hlsl_type
>> if (!v->arrays.count)
>> {
>> if (!(type = hlsl_type_clone(ctx, orig_type, 0,
>> modifiers)))
>> + {
>> + free_parse_variable_def(v);
>> return false;
>> + }
>
> And here too.
>
> Thanks, Giovanni.
>
Right, those should be "continue" rather than "return false". It can be
a follow-up patch, though.
More information about the wine-devel
mailing list