[PATCH vkd3d v4 2/8] vkd3d-shader/hlsl: Avoid leaks on memory allocation failures when parsing initializers.

Zebediah Figura zfigura at codeweavers.com
Wed Mar 9 14:17:01 CST 2022



On 3/9/22 14:10, Francisco Casas wrote:
> Hi,
> 
> March 9, 2022 3:51 PM, "Zebediah Figura" <zfigura at codeweavers.com> wrote:
> 
>>> @@ -3240,7 +3243,11 @@ initializer_expr_list:
>>> {
>>> $$ = $1;
>>> if (!($$.args = hlsl_realloc(ctx, $$.args, ($$.args_count + 1) * sizeof(*$$.args))))
>>> + {
>>> + free_parse_initializer(&$$);
>>> + destroy_instr_list($3);
>>> YYABORT;
>>> + }
>>> $$.args[$$.args_count++] = node_from_list($3);
>>> list_move_tail($$.instrs, $3);
>>> vkd3d_free($3);
>>
>> Unfortunately this still leaks the old $$.args (or $1.args). We should probably be using
>> array_reserve() here. There's a similar problem with 3/8.
> 
> If I am not mistaken, free_parse_initializer(&$$) takes care of that.
> Currently its definition is:
> ---
> static void free_parse_initializer(struct parse_initializer *initializer)
> {
>      destroy_instr_list(initializer->instrs);
>      vkd3d_free(initializer->args);
> }
> ---
> 
> Same for 3/8. Unless I am missing something...
> 

The problem is that you're assigning $$.args to NULL, so nothing is 
actually freed.



More information about the wine-devel mailing list