Giovanni Mascellani (@giomasce) commented about libs/vkd3d-shader/hlsl.c:
struct clone_instr_map *map, struct hlsl_ir_switch *s)
+{
- struct hlsl_ir_switch_case *c, *d;
- struct hlsl_ir_node *ret;
- struct hlsl_block body;
- struct list cases;
- list_init(&cases);
- LIST_FOR_EACH_ENTRY(c, &s->cases, struct hlsl_ir_switch_case, entry)
- {
clone_block(ctx, &body, &c->body, map);
if (!(d = hlsl_new_switch_case(ctx, NULL, &body, &c->loc)))
{
free_ir_switch_cases(&cases);
Here you have to cleanup `body`. If `hlsl_new_switch_case()` succeeds, than `body` is guaranteed to be empty, and you can just leave it go out of scope. But if `hlsl_new_switch_case()` fails because of memory allocation, this doesn't happen and you have to care about it in the caller. Alternatively, you can modify `hlsl_new_switch_case()` so that `body` is always cleaned up there. In other words, it must be clear whether `hlsl_new_switch_case()` takes ownership of `body` or not.