[PATCH vkd3d v5 2/8] vkd3d-shader/hlsl: Avoid leaks on memory allocation failures when parsing initializers.
Giovanni Mascellani
gmascellani at codeweavers.com
Mon Mar 14 07:34:00 CDT 2022
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
Il 10/03/22 16:14, Francisco Casas ha scritto:
> Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
>
> ---
> v5:
> - Preserve array pointer to correctly free memory on realloc failure.
>
> Signed-off-by: Francisco Casas <fcasas at codeweavers.com>
> ---
> libs/vkd3d-shader/hlsl.y | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index 92dcb3f2..aca246f6 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y
> @@ -3211,7 +3211,10 @@ complex_initializer:
> {
> $$.args_count = 1;
> if (!($$.args = hlsl_alloc(ctx, sizeof(*$$.args))))
> + {
> + destroy_instr_list($1);
> YYABORT;
> + }
> $$.args[0] = node_from_list($1);
> $$.instrs = $1;
> }
> @@ -3238,9 +3241,16 @@ initializer_expr_list:
> }
> | initializer_expr_list ',' initializer_expr
> {
> + struct hlsl_ir_node **new_args;
> +
> $$ = $1;
> - if (!($$.args = hlsl_realloc(ctx, $$.args, ($$.args_count + 1) * sizeof(*$$.args))))
> + if (!(new_args = hlsl_realloc(ctx, $$.args, ($$.args_count + 1) * sizeof(*$$.args))))
> + {
> + free_parse_initializer(&$$);
> + destroy_instr_list($3);
> YYABORT;
> + }
> + $$.args = new_args;
> $$.args[$$.args_count++] = node_from_list($3);
> list_move_tail($$.instrs, $3);
> vkd3d_free($3);
More information about the wine-devel
mailing list