Mesa (main): draw: fix double free of NIR IR

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 27 21:48:37 UTC 2022


Module: Mesa
Branch: main
Commit: 8d73315bce2d62b294df2403e95074be90b77407
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8d73315bce2d62b294df2403e95074be90b77407

Author: Charmaine Lee <charmainel at vmware.com>
Date:   Tue Apr 26 18:56:32 2022 -0700

draw: fix double free of NIR IR

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 <airlied at redhat.com>
Reviewed-by: Neha Bhende <bhenden at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16199>

---

 src/gallium/auxiliary/draw/draw_gs.c   | 2 +-
 src/gallium/auxiliary/draw/draw_tess.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_gs.c b/src/gallium/auxiliary/draw/draw_gs.c
index 1c969046fe8..66e10b077d2 100644
--- a/src/gallium/auxiliary/draw/draw_gs.c
+++ b/src/gallium/auxiliary/draw/draw_gs.c
@@ -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);
diff --git a/src/gallium/auxiliary/draw/draw_tess.c b/src/gallium/auxiliary/draw/draw_tess.c
index 9658e6f76ef..f42cd5799ce 100644
--- a/src/gallium/auxiliary/draw/draw_tess.c
+++ b/src/gallium/auxiliary/draw/draw_tess.c
@@ -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);
 }
@@ -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);
 }



More information about the mesa-commit mailing list