compiler/glsl: Use mutex lock while freeing up mem_ctx

builtin_builder::~builtin_builder() and builtin_builder::release()
are running into race condition. This leads lightsmark to crash at
the end because both calls ralloc_free which mutates the arguments state

This patch fixes lightsmark2008 crash

Fixes: e4da8b9c33 ("mesa/compiler: rework tear down of builtin/types")

Reviewed-by: Charmaine Lee <charmainel@vmware.com>
Reviewed-by: Neha Bhende <bhenden@vmware.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Tested-by: Neha Bhende <bhenden@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11385>
This commit is contained in:
Martin Krastev 2021-06-15 12:18:31 -07:00 committed by Marge Bot
parent 4a407e0ad8
commit eb272f6571

View file

@ -90,6 +90,8 @@
using namespace ir_builder;
static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
/**
* Availability predicates:
* @{
@ -1296,7 +1298,15 @@ builtin_builder::builtin_builder()
builtin_builder::~builtin_builder()
{
mtx_lock(&builtins_lock);
ralloc_free(mem_ctx);
mem_ctx = NULL;
ralloc_free(shader);
shader = NULL;
mtx_unlock(&builtins_lock);
}
ir_function_signature *
@ -7753,7 +7763,6 @@ builtin_builder::_helper_invocation()
/* The singleton instance of builtin_builder. */
static builtin_builder builtins;
static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
static uint32_t builtin_users = 0;
/**