mesa: Fix use after free.
authorMykola Piatykop <mykola.piatykop@globallogic.com>
Wed, 1 Mar 2023 14:48:45 +0000 (16:48 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 20 Jun 2023 04:13:43 +0000 (04:13 +0000)
Reset the pointer to the earlier free st_context.
Check the st_context pointer before st_glFlush.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8195

Signed-off-by: Mykola Piatykop <mykola.piatykop@globallogic.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21656>

src/mesa/main/context.c
src/mesa/state_tracker/st_context.c

index 2b810b0..dcae7f6 100644 (file)
@@ -1502,7 +1502,9 @@ _mesa_make_current( struct gl_context *newCtx,
        curCtx->Const.ContextReleaseBehavior ==
        GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH) {
       FLUSH_VERTICES(curCtx, 0, 0);
-      st_glFlush(curCtx, 0);
+      if (curCtx->st){
+         st_glFlush(curCtx, 0);
+      }
    }
 
    if (!newCtx) {
index 6f430ed..c61aa17 100644 (file)
@@ -371,6 +371,7 @@ st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
    if (st->pipe && destroy_pipe)
       st->pipe->destroy(st->pipe);
 
+   st->ctx->st = NULL;
    FREE(st);
 }