Skip to content

Commit

Permalink
draw: fix double free of NIR IR
Browse files Browse the repository at this point in the history
Check the shader IR type first before freeing the NIR IR in
draw_delete_xxx_shader() in case the IR has been converted to TGSI
and the NIR IR has already been freed.

Reviewed-by: Dave Airlie <[email protected]>
Reviewed-by: Neha Bhende <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16199>
  • Loading branch information
Charmaine Lee committed Apr 27, 2022
1 parent f4f350a commit 8d73315
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/gallium/auxiliary/draw/draw_gs.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ void draw_delete_geometry_shader(struct draw_context *draw,
for (i = 0; i < TGSI_MAX_VERTEX_STREAMS; i++)
FREE(dgs->stream[i].primitive_lengths);

if (dgs->state.ir.nir)
if (dgs->state.type == PIPE_SHADER_IR_NIR && dgs->state.ir.nir)
ralloc_free(dgs->state.ir.nir);
FREE((void*) dgs->state.tokens);
FREE(dgs);
Expand Down
4 changes: 2 additions & 2 deletions src/gallium/auxiliary/draw/draw_tess.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void draw_delete_tess_ctrl_shader(struct draw_context *draw,
}
#endif

if (dtcs->state.ir.nir)
if (dtcs->state.type == PIPE_SHADER_IR_NIR && dtcs->state.ir.nir)
ralloc_free(dtcs->state.ir.nir);
FREE(dtcs);
}
Expand Down Expand Up @@ -626,7 +626,7 @@ void draw_delete_tess_eval_shader(struct draw_context *draw,
align_free(dtes->tes_input);
}
#endif
if (dtes->state.ir.nir)
if (dtes->state.type == PIPE_SHADER_IR_NIR && dtes->state.ir.nir)
ralloc_free(dtes->state.ir.nir);
FREE(dtes);
}
Expand Down

0 comments on commit 8d73315

Please sign in to comment.